当前位置:  首页>> 技术小册>> Python合辑4-130个字符串操作示例

在 Python 中将字符串中每个单词的首字母大写

  1. import string
  2. x = "they're bill's friends from the UK"
  3. x = string.capwords(x)
  4. print(x)
  5. x = x.title()
  6. print(x)

Output:

  1. They're Bill's Friends From The Uk
  2. They'Re Bill'S Friends From The Uk

该分类下的相关小册推荐: