Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python String Case Conversion

Python String Case Conversion

Document Object Reference Manual Python3 Examples

The following code demonstrates how to convert a string to uppercase, or to lowercase, and so on:


# Filename : test.py
# author by : www.runoob.com

str = "www.runoob.com"
print(str.upper())          # 把所有字符中的小写字母转换成大写字母
print(str.lower())          # 把所有字符中的大写字母转换成小写字母
print(str.capitalize())     # 把第一个字母转化为大写字母,其余小写
print(str.title())          # 把每个单词的第一个字母转化为大写,其余小写 

The output of the code above is:


WWW.RUNOOB.COM
www.runoob.com
Www.runoob.com
Www.Runoob.Com

Document Object Reference Manual Python3 Examples