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

Python中列表中第一个单词的首字母大写

  1. text = ['johnny rotten', 'eddie vedder', 'kurt kobain',
  2. 'chris cornell', 'micheal phillip jagger']
  3. text = [txt.capitalize() for txt in text]
  4. print(text)

Output:

  1. ['Johnny rotten', 'Eddie vedder', 'Kurt kobain', 'Chris cornell', 'Micheal phillip jagger']

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