Search code examples
pythonif-statementcase-insensitive

How To Make An If Statement Case Insensitive In Python


It can become quite tedious to put multiple variations of spelling into and if statement and I was wondering if there is a way I could make the if statements case insensitive so I only need to put in one thing. I'm just picking up python again and couldn't find a good way online.


Solution

  • In [2]: s = 'aBcDe'                                                                                                                                                                                                                                                                                                           
    
    In [3]: if s.lower() == 'abcde': 
       ...:     print("look! it's case insensitive") 
       ...:                                                                                                                                                                                                                                                                                                                       
    look! it's case insensitive