0

Here is my sample code I'm learning. I want to take a string (1 or more characters) and compare it against the existing string. I want to enter blue and still get the answer. How to ignore the case completely? Thanks.

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 ")

for a success case:

C:\PythonMasterClass>python IfProgramFlow.py  
Enter a character: Blue  
The letter Blue is in the Norwegian Blue

and for the failed case:

C:\PythonMasterClass>python IfProgramFlow.py  
Enter a character: blue  
Sorry the letter is missing

I've checked other threads to convert my inputs and actual text to lower case and compare against, but I wanted a straight way. What If I have multiple strings, I don't want to save all of them in lower case for this purpose. Thanks.

raja777m
  • 401
  • 1
  • 8
  • 18

1 Answers1

7

Try: if letter.lower() in parrot.lower():

Josep Valls
  • 5,483
  • 2
  • 33
  • 67
  • Saw that this morning, I just wanted to get a straight way like in Java to match the string. Thanks. – raja777m Dec 04 '18 at 20:07