是否有更短的方法来检查字符串中的字符?谢谢:D
check = input("Put in the letter: ")
word = "word"
if(check == word[0]):
print(check)
if(check == word[1]):
print(check)
if(check == word[2]):
print(check)
if(check == word[3]):
print(check)
答案 0 :(得分:5)
这个怎么样:
if check in word:
print(check)
答案 1 :(得分:4)
像
这样的东西for l in word:
if l == check:
print (check)
也许?