这是我正在学习的示例代码。我想获取一个字符串(1个或多个字符)并将其与现有字符串进行比较。我想进入蓝色并且仍然得到答案。如何完全无视案件? 谢谢。你知道吗
parrot = "Norwegian Blue"
letter = input("Enter a character: ")
if letter in parrot:
print("The letter {0} is in the Norwegian Blue".format(letter))
else:
print("Sorry the letter is missing ")
对于成功案例:
C:\PythonMasterClass>python IfProgramFlow.py
Enter a character: Blue
The letter Blue is in the Norwegian Blue
对于失败的案例:
C:\PythonMasterClass>python IfProgramFlow.py
Enter a character: blue
Sorry the letter is missing
我已经检查了其他线程,将我的输入和实际文本转换为小写,并与之进行比较,但我想要一个直接的方法。 如果我有多个字符串,我不想为了这个目的用小写保存它们。 谢谢。你知道吗
试试:
if letter.lower() in parrot.lower():
相关问题 更多 >
编程相关推荐