How do I do a case-insensitive string comparison?

前端 未结 9 2199
无人及你
无人及你 2020-11-21 07:46

How can I do case insensitive string comparison in Python?

I would like to encapsulate comparison of a regular strings to a repository string using in a very simple

9条回答
  •  失恋的感觉
    2020-11-21 08:33

    The usual approach is to uppercase the strings or lower case them for the lookups and comparisons. For example:

    >>> "hello".upper() == "HELLO".upper()
    True
    >>> 
    

提交回复
热议问题