溫馨提示×

Python中字符串轉(zhuǎn)換大小寫的方法是什么

小億
87
2024-04-02 18:15:01
欄目: 編程語言

Python中字符串轉(zhuǎn)換大小寫的方法有三種:

  1. 使用upper()方法將字符串轉(zhuǎn)換為大寫。例如:
s = "hello"
s_upper = s.upper()
print(s_upper)  # 輸出:HELLO
  1. 使用lower()方法將字符串轉(zhuǎn)換為小寫。例如:
s = "HELLO"
s_lower = s.lower()
print(s_lower)  # 輸出:hello
  1. 使用title()方法將字符串中每個(gè)單詞的首字母轉(zhuǎn)換為大寫。例如:
s = "hello world"
s_title = s.title()
print(s_title)  # 輸出:Hello World

0