Python中定义函数的方式非常简单,参数定义方式也相对较为灵活。
def power(x):
return x * x
def enroll(name, gender, age=6, city='Beijing'):
print('name:', name)
print('gender:', gender)
print('age:', age)
print('city:', city)
def calc(*numbers):
sum = 0
for n in numbers:
sum = sum + n * n
return sum
def person(name, age, **kw):
print('name:', name, 'age:', age, 'other:', kw)
def person(name, age, *, city, job):
print(name, age, city, job)
我还会回来更新的今天不想改Blog了嗷
参考: https://www.liaoxuefeng.com/wiki/1016959663602400/1017261630425888