我想知道这样为什么没输出
def firstCharUpper(*args):
for s in args
return s[0].upper()+s[1:].lower()
print firstCharUpper('hello','bob')
print firstCharUpper('sunday')
print firstCharUpper('september')
def firstCharUpper(*args):
for s in args
return s[0].upper()+s[1:].lower()
print firstCharUpper('hello','bob')
print firstCharUpper('sunday')
print firstCharUpper('september')
2017-03-16
这样改了还是不对,你的return对这个函数返回处理了,针对多个元素的list,它会返回第一个就执行完毕,所以若按你那样,输出将不会有bob,要改成: def firstCharUpper(*args): l=[] for s in args: l.append(s[0].upper()+s[1:].lower()) return l print firstCharUpper('hello','bob') print firstCharUpper('sunday') print firstCharUpper('september') >>>('hello','bob') >>>('sunday') >>>('september')
举报