Python3.x代码的简短版本
有没有更简短的方法来检查字符串中的字符?谢谢:DPython3.x代码的简短版本,python,Python,有没有更简短的方法来检查字符串中的字符?谢谢: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) 差不多 for l in wor
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)
差不多
for l in word:
if l == check:
print (check)
也许吧?这个怎么样:
if check in word:
print(check)
快速提示:@leistungsabfall的代码将打印字符一次,尽管它可能会出现多次,而我的代码与您的原始代码一样,如果字母在单词中出现多次,则会打印n次。这并不完全相同,例如,如果
word='HELLO'
和check='L'