python

python大小写转换怎么实现

小亿
82
2023-12-08 00:35:22
栏目: 编程语言

在Python中,可以使用lower()方法将字符串转换为小写,upper()方法将字符串转换为大写。以下是实现大小写转换的示例代码:

# 将字符串转换为小写
string = "HELLO"
lower_case = string.lower()
print(lower_case)  # 输出 "hello"

# 将字符串转换为大写
string = "world"
upper_case = string.upper()
print(upper_case)  # 输出 "WORLD"

这些方法返回转换后的新字符串,原始字符串不会发生更改。

0
看了该问题的人还看了