我需要输入一个输入句子,例如:Hello world,星期一。并输出:hELLO世界现在是星期一。如果单词以大写字母开头,我基本上需要交换大小写。我知道如何交换大小写,但是.isupper()始终返回false。
x = str(input("Enter your sentence please. "))
y = x.split(" ")
print(y)
######THIS OUTPUTS FALSE NO MATTER WHAT
for i in range(0,len(y)):
if y[i].isupper() == True:
print("True")
else:
print("False")
您需要:
a = "Hello world its Monday"
x = [i.swapcase() if i[0].isupper() else i for i in a.split()]
print(" ".join(x))
输出:
hELLO world its mONDAY