小册名称:Python合辑4-130个字符串操作示例
在Python中随机大写字符串中的字母
from random import choicex = "canada japan australia"print(''.join(choice((str.upper, str.lower))(c) for c in x))
from random import choice
x = "canada japan australia"
print(''.join(choice((str.upper, str.lower))(c) for c in x))
Output:
CANaDA JaPan auStRALIa