使用这个脚本:
color = 'blue'
def say_color(color):
print 'The color is: ' + color
say_color()
在这里,我试图允许在不传递参数的情况下处理 say_color
,结果是默认颜色(蓝色)。但是,如果指定了颜色,它将不会使用蓝色,而是使用给定的字符串。
这是怎么做到的?
最佳答案
def say_color(color='blue'):
print 'The color is: ' + color
say_color()
关于python - 分配默认参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10767446/