一行Python生成随机字符串

一行Python代码生成随机字符串:

import random, string; print(''.join(random.choice(string.ascii_letters + string.digits) for _ in range(15)))
# python -c "import random, string; print(''.join(random.choice(string.ascii_letters + string.digits) for _ in range(15)))"
hTvLXAGUzTISKmZ

如果是Python3,还可以使用:

import random, string; print(''.join(random.choices(string.ascii_letters + string.digits, k=15)))
# python3 -c "import random, string; print(''.join(random.choices(string.ascii_letters + string.digits, k=15)))"            
BRYr0FncnkXUL9F