Search code examples
pythoninputuppercaselowercase

Does python HAVE to be case sensitive?


When a user inputs a command using:

input()

Is it possible within python to make it so that the case in which they enter the command does not matter?

eg:

print("Do you Shout? Look? Continue?")
action1 = input()
if action1 == "Continue":

Can I make it so that if they enter "continue" (in lower case) this section of code will still work? Thanks in advance for responses!


Solution

  • I would suggest sticking with a single case when checking. So you should use "continue". Keep it all using a single case (in this case lower case), by using either lower() or upper() to control the casing, to ensure your conditions are matched exactly as you expect.

    print("Do you Shout? Look? Continue?")
    action1 = input()
    if action1.lower() == "continue":
        # do things