Home >Backend Development >Python Tutorial >How to use function to determine case in Python

How to use function to determine case in Python

(*-*)浩
(*-*)浩Original
2019-07-04 14:11:4712414browse

Python provides isupper(), islower(), and istitle() methods to determine the case of a string. The specific examples are as follows:

How to use function to determine case in Python

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!

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