我想问一下如何在python中调用带有两个参数的函数。例如,
下面的代码是我想调用颜色函数的一个示例。如何在Python中调用带有两个参数的函数
def color(object):
return '\033[1;34m'+object+'\033[1;m'
tes = 'this must be blue'
print color(tes)
但这仅仅是一个参数。 然后我想用不同的颜色选择两个参数。 下面是我的虚拟代码。
def color(object,arg2):
blue = '\033[1;34m'+object+'\033[1;m'
red = '\033[1;31m'+object+'\033[1;m'
tes = 'this must be blue'
tes_2 = 'i wanna this string into red!!'
print color(tes,red)
很好,这只是我的虚拟代码和这将是类似这样的错误..
print color(tes,red)
NameError: name 'red' is not defined
你能告诉我如何在蟒蛇一个运行良好的? TY
写'red ='而不是'tes_2 =' – 2012-03-10 15:45:09
你真的想要'color(arg1,arg2)'返回什么? – 2012-03-10 15:51:08
取决于我定义了一个新的变量。 只是出来的颜色可以用两个参数来调用。已经在函数中定义了。 – user1070579 2012-03-10 15:53:55