to inspire confidence in somebody.

0%

一行Python生成随机字符串

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

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

如果是Python3,还可以使用:

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