共計 277 個字符,預(yù)計需要花費 1 分鐘才能閱讀完成。
Python 中字符串轉(zhuǎn)換大小寫的方法有三種:
- 使用 upper() 方法將字符串轉(zhuǎn)換為大寫。例如:
s = "hello"
s_upper = s.upper()
print(s_upper) # 輸出:HELLO
- 使用 lower() 方法將字符串轉(zhuǎn)換為小寫。例如:
s = "HELLO"
s_lower = s.lower()
print(s_lower) # 輸出:hello
- 使用 title() 方法將字符串中每個單詞的首字母轉(zhuǎn)換為大寫。例如:
s = "hello world"
s_title = s.title()
print(s_title) # 輸出:Hello World
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完