我对 python 有点陌生 - 我至少认为我对语法有扎实的理解,但似乎无法弄清楚为什么这个函数不起作用。
我想写一个函数来将字符串中的字母大写。
string = 'Bryan'
def caps(word):
word.upper()
caps(string)
我在这里不明白什么?对我来说似乎很基本,但无法弄清楚。任何帮助将不胜感激!
请您参考如下方法:
您需要明确指定返回。
替换
word.upper()
与
return word.upper()
如果没有指定return语句,默认返回None,即为结果。
string = 'Bryan'
def caps(word):
return word.upper()
returning_value = caps(string) #Note that you need to catch the returning the value.
print returning_value
