Files
Python_CookBook_repo/7.函数/2.编写只接受关键字参数的函数.py
2025-09-10 16:12:45 +08:00

14 lines
292 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 在*参数和**参数之间可以加入普通参数这种普通参数被称为keyword_only参数
def recv(maxsize, *, block):
print("recv msg")
pass
# 这类参数只能被指定输入,示例如下:
recv(1024, True) # 报错TypeError
recv(1024, block=True) # 正确