How to convert string case in python

爱喝马黛茶的安东尼
Release: 2019-06-17 15:15:10
Original
18759 people have browsed it

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="www.php.cn."
>>> print(str.upper())   # 把所有字符中的小写字母转换成大写字母
WWW.PHP.CN.
>>> print(str.lower()) # 把所有字符中的大写字母转换成小写字母
www.php.cn.
>>> print(str.capitalize())# 把第一个字母转化为大写字母,其余小写
Www.php.cn.
>>> print(str.title())    # 把每个单词的第一个字母转化为大写,其余小写
Www.Php.Cn.
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template