-5
如果有任何大写字母,它会将所有字更改为大写,否则,如果没有大写字,它会再次打印而不更改,因此我写这个代码如何从循环中获取结果(python)
def capital(n):
for word in n:
if word==word.upper():
print n.upper()
else:
print n
n=raw_input()
print capital(n)
输出是这样的,当我使用的,而不是返回
capsLock # if i use return it pritn the first result only
capsLock
capsLock
capsLock
capsLock
CAPSLOCK # i want this result when it change all letter to capital words
capsLock
capsLock
capsLock
None
打印如果我使用返回它给我的只有第一个结果是我应该做的
构建一个新列表's.upper()for s in],并打印出来。或者使用'map':'map(lambda x:x.upper(),n)' – Maroun
@MarounMaroun如果你要“映射”,只需使用map(str.upper,n)'。 – jonrsharpe
@jonrsharpe每天我都会学习新的东西:)谢谢。 – Maroun