#python3 win10
def yy(background=0,bg=0):
'''
默认值参数别名的实现
'''
res = background if background != 0 else bg
return res
print(yy(background=3))
print(yy(bg=3))
#------------
def yy1(background=0,bg=0):
'''
默认值参数别名的实现 方法1
'''
res = background and bg
# res = background and bg #也行,0为假
# 相当于 res = (background and bg)
# (background and bg) 逻辑连接,and,一假则假,(逻辑运算倾向于取'真',返回值是从左到右顺序直到为真(and))
return res
print(yy(background=3))
print(yy(bg=3))
python 默认值参数 别名 多个名称同时表示一个参数
猜你喜欢
转载自blog.csdn.net/qq_35515661/article/details/83985513
今日推荐
周排行