python3 字符串转大写
时间: 2023-09-29 07:06:34 浏览: 35
Python3 中可以使用字符串对象的 `upper()` 方法将字符串转换为大写形式。例如:
```
s = "hello world"
s_upper = s.upper()
print(s_upper) # 输出 "HELLO WORLD"
```
在这个例子中,我们将字符串 `s` 转换为大写形式并将结果存储在变量 `s_upper` 中。然后使用 `print()` 函数将结果输出到控制台。
相关问题
python字符串转大写
在Python中,可以使用字符串的`upper()`方法将字符串转换为大写。`upper()`方法返回一个新的字符串,其中所有的字母都被转换为大写形式。
以下是一个示例代码:
```python
string = "hello world"
uppercase_string = string.upper()
print(uppercase_string)
```
输出结果为:
```
HELLO WORLD
```
python 字符串大写转小写
在Python中,可以使用`lower()`方法将字符串中的大写字母转换为小写字母。以下是一个示例:
```python
string = "HELLO WORLD"
lowercase_string = string.lower()
print(lowercase_string)
```
输出结果为:
```
hello world
```
相关推荐
![](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)