扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python怎么修改字符串中的字符大小

扬州沐宇科技
2024-05-28 13:53:08
python

要修改字符串中字符的大小,可以使用字符串的 upper()lower()capitalize() 方法。

  1. 使用 upper() 方法将字符串中的所有字符都转换为大写:
string = "hello"
new_string = string.upper()
print(new_string)  # 输出: HELLO
  1. 使用 lower() 方法将字符串中的所有字符都转换为小写:
string = "WORLD"
new_string = string.lower()
print(new_string)  # 输出: world
  1. 使用 capitalize() 方法将字符串的第一个字符转换为大写,其他字符转换为小写:
string = "hello world"
new_string = string.capitalize()
print(new_string)  # 输出: Hello world

扫码添加客服微信