1. `upper()` 方法:将字符串中的所有字母转换为大写。
text = "hello, world!"
print(text.upper()) 输出:HELLO, WORLD!
2. `lower()` 方法:将字符串中的所有字母转换为小写。
text = "HELLO, WORLD!"
print(text.lower()) 输出:hello, world!
3. `capitalize()` 方法:将字符串的首字母转换为大写,其余字母转换为小写。
text = "hello world"
print(text.capitalize()) 输出:Hello world
4. `title()` 方法:将字符串中每个单词的首字母转换为大写,其余字母转换为小写。
text = "c.biancheng.net"
print(text.title()) 输出:C.Biancheng.Net
5. `swapcase()` 方法:将字符串中的大写字母转换为小写字母,小写字母转换为大写字母。
text = "Hello World"
print(text.swapcase()) 输出:hELLO wORLD
以上方法都会返回一个新的字符串,原始字符串不会被修改