上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 37 下一页
摘要: ## 7. 函数编写指南 - 给函数指定描述性名称。 - 函数的注释采用文档字符串格式,简要阐述函数的功能。 - 给形参指定默认值时,等号两边不要有空格。函数调用中的关键字实参也是这样。 - 代码行的长度不要超过79个字符。如果形参很多,可采用以下格式 ``` def function_name( 阅读全文
posted @ 2023-07-08 23:40 钱塘江畔 阅读(26) 评论(0) 推荐(0)
摘要: ## 4. 传递列表 ``` def greet_users(names): """向列表中的每位用户发出问候。""" for name in names: msg = f"Hello, {name.title()}" print(msg) usernames = ['hanks', 'jackso 阅读全文
posted @ 2023-07-08 23:34 钱塘江畔 阅读(34) 评论(0) 推荐(0)
摘要: ## 1. 示例 ``` def greet_user(): # 函数定义 """显示简单的问候语""" # 文档字符串,描述了函数的功能。Python基于此生成有关函数的文档 print("Hello!") greet_user() ``` #### 1.1 参数 ``` def greet_us 阅读全文
posted @ 2023-07-08 22:31 钱塘江畔 阅读(35) 评论(0) 推荐(0)
摘要: # 使用while处理列表和字典 ## 1. 在列表之间移动元素 在for循环遍历列表时,若修改列表元素会导致Python难以跟踪元素。 ``` unconfirmed_users = ['alice', 'brian', 'candace'] confirmed_users = [] for un 阅读全文
posted @ 2023-07-08 20:48 钱塘江畔 阅读(47) 评论(0) 推荐(0)
摘要: ## 1. 示例 ``` current_number = 1 while current_number 避免无限循环 阅读全文
posted @ 2023-07-08 20:00 钱塘江畔 阅读(41) 评论(0) 推荐(0)
摘要: ## 1. 示例 ``` message = input("tell me something, and I will repeat it back to you: ") print(message) ``` #### 1.1 提示 - prompt ``` prompt = "If you tel 阅读全文
posted @ 2023-07-08 10:43 钱塘江畔 阅读(51) 评论(0) 推荐(0)
摘要: ## 1. 字典列表 ``` alien_0 = {'color': 'green', 'points':5} alien_1 = {'color': 'yellow', 'points':10} alien_2 = {'color': 'red', 'points':15} aliens = [a 阅读全文
posted @ 2023-07-07 18:35 钱塘江畔 阅读(36) 评论(0) 推荐(0)
摘要: ## 1.示例 ``` alien_0 = {'color':'green', 'points':5} print(alien_0['color']) print(alien_0['points']) ``` ## 2.使用字典 字典就是一系列**键值对**,每个键与一个值相关联,可以通过键来访问相 阅读全文
posted @ 2023-07-07 17:53 钱塘江畔 阅读(17) 评论(0) 推荐(0)
摘要: ## 1. 示例 ``` cars = ['audi', 'bmw', 'subaru', 'toyota'] for car in cars: if car == 'bmw': print(car.upper()) else: print(car.title()) ``` ## 2. 条件测试 布 阅读全文
posted @ 2023-07-07 15:43 钱塘江畔 阅读(68) 评论(0) 推荐(0)
摘要: [引用](https://blog.csdn.net/lyfGeek/article/details/106592636) 阅读全文
posted @ 2023-07-07 00:16 钱塘江畔 阅读(14) 评论(0) 推荐(0)
上一页 1 ··· 16 17 18 19 20 21 22 23 24 ··· 37 下一页