2025-09-10:仓库迁移
This commit is contained in:
16
7.函数/1.编写可接受任意数量参数的函数.py
Normal file
16
7.函数/1.编写可接受任意数量参数的函数.py
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
|
||||
# 要编写一个接受任意数量参数的函数,可以使用*
|
||||
def avg(first, *rest):
|
||||
return (first + sum(rest))/(len(rest) + 1)
|
||||
|
||||
# 如果是关键字类型的参数,那就需要使用**
|
||||
def make_element(name, value, **attrs):
|
||||
for item in attrs.items():
|
||||
print("'{} = {}'".format(*item))
|
||||
return 0
|
||||
|
||||
# *与**有使用上的限制,它们必须在所有参数的最后,**必须在*后面
|
||||
def anyargs(*args, **kwargs):
|
||||
print(args)
|
||||
print(kwargs)
|
Reference in New Issue
Block a user