Home >Backend Development >Python Tutorial >How to convert string case in python

How to convert string case in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-10 14:08:2918799browse

In python, the method of converting string case to upper and lower case is very simple. Let me demonstrate it to you below:

How to convert string case in python


upper() converts lowercase letters to uppercase letters; lower() converts uppercase letters to lowercase letters; capitalize() only converts the first letter to uppercase; title() converts each word Convert the first letter to uppercase and the rest to lowercase.

Take PHP as an example and demonstrate it under shell:

>>> str="m.sbmmt.com."
>>> print(str.upper())   # 把所有字符中的小写字母转换成大写字母
WWW.PHP.CN.
>>> print(str.lower()) # 把所有字符中的大写字母转换成小写字母
m.sbmmt.com.
>>> print(str.capitalize())# 把第一个字母转化为大写字母,其余小写
Www.php.cn.
>>> print(str.title())    # 把每个单词的第一个字母转化为大写,其余小写
Www.Php.Cn.

The above is the detailed content of How to convert string 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