简体   繁体   中英

Python string search case insensitive

I am trying to have a program react dependent on what the user types but i do not want it to be case sensitive eg

MenuOption = input("Login or Register or Press 'Q' to quit")
while MenuOption != "login" and MenuOption != "register" and MenuOption!= "q":
    print("Please enter one of the two options")
    MenuOption = input("Login or Register")

the program only allows you access if you type in lowecase but I do not want the case of the letters to affect it at all so you could type in "lOgIN" and it would still read that as login.

Thanks guys!

Use the .lower() method, eg MenuOption.lower() . This will convert the input string to all lowercase letters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM