1. `upper()` 方法:将字符串中的所有字母转换为大写。
```python
text = "hello, world!"
text_upper = text.upper()
print(text_upper) 输出:HELLO, WORLD!
2. `lower()` 方法:将字符串中的所有字母转换为小写。
```python
text = "HELLO, WORLD!"
text_lower = text.lower()
print(text_lower) 输出:hello, world!
3. `capitalize()` 方法:将字符串的首字母转换为大写,其余字母转换为小写。
```python
text = "hello world"
text_capitalize = text.capitalize()
print(text_capitalize) 输出:Hello world
4. `swapcase()` 方法:将字符串中的大写字母转换为小写字母,小写字母转换为大写字母。
```python
text = "Hello World"
text_swapcase = text.swapcase()
print(text_swapcase) 输出:hELLO wORLD
5. `title()` 方法:将字符串中每个单词的首字母转换为大写,其余字母转换为小写。
```python
text = "hello world"
text_title = text.title()
print(text_title) 输出:Hello World
以上方法都会返回一个新的字符串,原始字符串不会被修改。如果需要在原字符串上进行修改,可以将新字符串赋值给原字符串变量