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

在Python中随机大写字符串中的字母

  1. from random import choice
  2. x = "canada japan australia"
  3. print(''.join(choice((str.upper, str.lower))(c) for c in x))

Output:

  1. CANaDA JaPan auStRALIa

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