小册名称:Python合辑4-130个字符串操作示例
在 Python 中将字符串中每个单词的首字母大写
import stringx = "they're bill's friends from the UK"x = string.capwords(x)print(x)x = x.title()print(x)
import string
x = "they're bill's friends from the UK"
x = string.capwords(x)
print(x)
x = x.title()
Output:
They're Bill's Friends From The UkThey'Re Bill'S Friends From The Uk
They're Bill's Friends From The Uk
They'Re Bill'S Friends From The Uk