摘要:
## 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)

浙公网安备 33010602011771号