How to match a substring in a string, ignoring case

后端 未结 8 1809
既然无缘
既然无缘 2020-12-08 12:58

I\'m looking for ignore case string comparison in Python.

I tried with:

if line.find(\'mandy\') >= 0:

but no success for ignore

8条回答
  •  清歌不尽
    2020-12-08 13:18

    If you don't want to use str.lower(), you can use a regular expression:

    import re
    
    if re.search('mandy', 'Mandy Pande', re.IGNORECASE):
        # Is True
    

提交回复
热议问题