python变成大写
时间: 2024-03-29 21:33:49 浏览: 20
要将Python字符串转换为大写,可以使用字符串的`upper()`方法。这个方法会返回一个将所有小写字母转换为大写字母的新字符串。下面是一个示例:
```python
string = "python"
uppercase_string = string.upper()
print(uppercase_string) # 输出 "PYTHON"
```
相关问题
python大写变小写
可以使用 lower() 函数将 Python 字符串中的大写字母转换为小写字母。具体方法:在需要转换的字符串末尾添加 .lower() 即可。例如:
```
string = "PYthOn"
new_string = string.lower()
print(new_string)
```
输出为 "python"。
python小写字母变成大写
可以使用字符串的 `upper()` 方法将小写字母转换为大写字母。比如:
```python
s = "hello world"
s = s.upper()
print(s) # 输出 "HELLO WORLD"
```
另外,还可以使用 `str.capitalize()` 方法将字符串的首字母大写,其余字母小写。比如:
```python
s = "hello world"
s = s.capitalize()
print(s) # 输出 "Hello world"
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)