随机生成10位数密码,字母和数字组合
import string
>>> import random
>>> pwd = ""
>>> letters=string.ascii_letters+string.digits
>>> for i in range(10):
... letter=random.choice(letters)
... pwd += letter
...
>>> print(pwd)
利用推导列表生成
"".join([random.choice(string.ascii_letters+string.digits) for i in range(10)])