在Python中,可以使用lower()
方法将字符串转换为小写,upper()
方法将字符串转换为大写。以下是实现大小写转换的示例代码:
# 将字符串转换为小写
string = "HELLO"
lower_case = string.lower()
print(lower_case) # 输出 "hello"
# 将字符串转换为大写
string = "world"
upper_case = string.upper()
print(upper_case) # 输出 "WORLD"
这些方法返回转换后的新字符串,原始字符串不会发生更改。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: python怎么导入cos函数