In python, the method of converting string case to upper and lower case is very simple. Let me demonstrate it to you below:
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.
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!