大小写转换

基本类型 / 字符串

from string import capwords

text = "Lower And Upper"

lower = text.lower()
# lower is 'lower and upper'

upper = text.upper()
# upper is 'LOWER AND UPPER'

capitalize = text.capitalize()
# capitalize is 'Lower and upper'

swap_case = text.swapcase()
# swap_case is 'lOWER aND uPPER'

# Every word capitalized
title = lower.title()
# title is 'Lower And Upper'

# title() restarts after an apostrophe
bad_title = "they're".title()
# bad_title is "They'Re"
good_title = capwords("they're")
# good_title is "They're"

print(f"{lower = }")
print(f"{upper = }")
print(f"{capitalize = }")
print(f"{swap_case = }")
print(f"{title = }")
print(f"{bad_title = }")
print(f"{good_title = }")