随笔分类 -  python

摘要:7.1 创建和使用类 class Dog(): # 一次模拟小狗的简单尝试””" def_init_(self,name,age): # "“初始化属性name,age""" self.name = name self.age = age def sit(self): # ""模拟小狗收到命令时蹲下 阅读全文
posted @ 2024-07-28 07:14 鹤比纷恆红 阅读(25) 评论(0) 推荐(0) 编辑
摘要:6.1 定义函数 def greet_user(): """显示简单的问候语""" print('Hello!') greet_user() # 调用函数 6.1.1 向函数传递信息 def greet_user(username): "“显示简单的问候语"” print(f"Hello,{user 阅读全文
posted @ 2024-07-27 17:53 鹤比纷恆红 阅读(12) 评论(0) 推荐(0) 编辑
摘要:5.1 函数input()工作原理 # 变量=input(参数:说明/提示) message input("Tell me something,and I will repeat it back to you:" print(message) prompt ="If you tell us who 阅读全文
posted @ 2024-07-27 16:17 鹤比纷恆红 阅读(10) 评论(0) 推荐(0) 编辑
摘要:4.1 一个简单的字典(键值对) # 外星人颜色(绿色)+分数(5) alien_0 = {'color':'green','points':5} print(alien_0['color']) #想要获取值(green),指定字典名(alie_0)+键(color) print(alien_0[' 阅读全文
posted @ 2024-07-27 15:06 鹤比纷恆红 阅读(20) 评论(0) 推荐(0) 编辑
摘要:3.1 一个简单实例 cars = ['audi','bmw','subaru','toyota'] for car in cars: if car == 'bmw': pirnt(car.upper()) else: pirnt(car.title()) Audi BMW Subaru Toyot 阅读全文
posted @ 2024-07-03 16:24 鹤比纷恆红 阅读(25) 评论(0) 推荐(0) 编辑
摘要:2.1 列表是什么 bicycles = ['trek','cannondale','redline','specialized'] print(bicycles) 结果:['trek','cannondale','redline','specialized'] ① 访问列表元素 bicycles 阅读全文
posted @ 2024-07-03 14:38 鹤比纷恆红 阅读(20) 评论(0) 推荐(0) 编辑
摘要:1.1 变量的命名和适用 ① 必须是字母,数字,下划线。不能数字开头 message = "xxxx" 1_message = "xxxx"(不行) _message = "xxx" 0 = "xxx"(不行) ② 常变量名之间不能有空格 greeting message = "xxx"(不行) g 阅读全文
posted @ 2024-07-01 15:53 鹤比纷恆红 阅读(7) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示