Home >Backend Development >Python Tutorial >How to use function to determine case in Python
Python provides isupper(), islower(), and istitle() methods to determine the case of a string. The specific examples are as follows:
For example : (Recommended learning: Python video tutorial)
>>> str_1 = "HELLO PYTHON" # 全大写 >>> str_2 = "Hello PYTHON" # 大小写混合 >>> str_3 = "Hello Python" # 单词首字母大写 >>> str_4 = "hello python" # 全小写
isupper() determines whether it is all uppercase
>>> str_1.isupper() True >>> str_2.isupper() False >>> str_3.isupper() False >>> str_4.isupper() False
islower() determines whether all lowercase letters
>>> str_1.islower() False >>> str_2.islower() False >>> str_3.islower() False >>> str_4.islower() True
istitle() determines whether the first letter is capitalized and the rest is lowercase
>>> str_1.istitle() False >>> str_2.istitle() False >>> str_3.istitle() True >>> str_4.istitle() False
For more Python-related technical articles, please visit the Python Tutorial column to learn!
The above is the detailed content of How to use function to determine case in Python. For more information, please follow other related articles on the PHP Chinese website!