变更
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
# 函数的多返回值
|
||||
# def test_return():
|
||||
# return 1,"hello",True
|
||||
#
|
||||
# x,y,z=test_return()
|
||||
# print(x)
|
||||
# print(y)
|
||||
# print(z)
|
||||
|
||||
# 函数的多种传参方式
|
||||
def user_info(name, age, gender):
|
||||
print(f"姓名是{name},年龄是{age},性别是{gender}")
|
||||
|
||||
|
||||
# 位置参数
|
||||
user_info('小明', 23, '男')
|
||||
# 关键字参数
|
||||
user_info(name='小王', age=33, gender='男')
|
||||
user_info('小王', age=23, gender='女')
|
||||
|
||||
|
||||
# 缺省参数
|
||||
def user_info1(name, age, gender='男'):
|
||||
print(f"姓名是{name},年龄是{age},性别是{gender}")
|
||||
|
||||
|
||||
user_info1('小王', 23)
|
||||
|
||||
|
||||
# 不定长参数
|
||||
def user_info2(*args):
|
||||
print(f"{args},{type(args)}")
|
||||
|
||||
|
||||
user_info2(1, 2, 3, '小王')
|
||||
|
||||
|
||||
def user_info3(**kwargs):
|
||||
print(kwargs)
|
||||
print(type(kwargs))
|
||||
|
||||
|
||||
user_info3(姓名='小王', age=11, gender=23)
|
||||
|
||||
# 匿名函数
|
||||
# 函数作为参数传递
|
||||
def test_func(computer):
|
||||
result=computer(1,2)
|
||||
print(result)
|
||||
|
||||
|
||||
def computer(x,y):
|
||||
return x+y
|
||||
|
||||
|
||||
test_func(computer)
|
||||
#lambad匿名函数
|
||||
def test_func1(computer):
|
||||
result=computer(1,2)
|
||||
print(result)
|
||||
|
||||
test_func1(lambda x,y:x*y)
|
||||
Reference in New Issue
Block a user