Search code examples
pythonstringcomparecase-insensitive

Case-insensitive string comparison without using lower or upper


I am trying to compare two string and ignore case- sensitive but i don't want to use .lower() or .upper(). Is there another way of doing this?


Solution

  • example1 = "hello"
    example2 = "HeLlo"
    
    if example1.casefold()==example2.casefold():
        #do something
    

    This will work without needing upper() or lower(). Might not work for non-ASCII characters.