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

在Python中将字符串中的一些小写字母更改为大写

  1. indices = set([0, 7, 14, 18])
  2. s = "i love canada and japan"
  3. print("".join(c.upper() if i in indices else c for i, c in enumerate(s)))

Output:

  1. I love Canada And Japan

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