Home  >  Article  >  Backend Development  >  How to ignore case in python

How to ignore case in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-22 14:59:269456browse

How to ignore case in python

#How to ignore case in python? Here are two methods for you:

1. Regular expression, use IGNORECASE flag

>>> import re
>>> m = re.search('multi', 'A mUltiCased string', re.IGNORECASE)
>>> bool(m)

Related recommendations:《 Python video tutorial

2. Convert the two strings to the same uppercase before comparison, use the upper() method, or lowercase, lower()

>>> s = 'A mUltiCased string'.lower()
>>> s
'a multicased string'
>>> s.find('multi')
2

The above is the detailed content of How to ignore case in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn