标签:image 生成 asc span ima ring case byte 开始
[i ** 2 for i in range(1,11)] [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
lst = [1,4,9,16,2,5,10,15] [lst[i] + lst[i+1] for i in range(len(lst) - 1)]
[print("{} * {} = {} {}".format(j,i,i*j,"\n" if i == j else ‘ ‘),end=‘‘) for i in range(1,10) for j in range(1,i+1)]
print("\n".join([‘ ‘.join(["{} * {} = {:<2}".format(j,i,i*j) for j in range(1,i+1)]) for i in range(1,10) ]))
使用string模块
import string alpha = string.ascii_lowercase print(alpha) #abcdefghijklmnopqrstuvwxyz
使用chr()函数
"".join(chr(i) for i in range(97,123))
使用内嵌函数bytes()
bytes((i for i in range(97,123))).decode() bytes(range(97,123)).decode()
"0001.dfafdedeff"是ID的格式,要求ID格式是点分隔,左边是4位从1开始,后边是10位随机的字母,生成10个
import string import random #生成随机的10个字母 "".join(random.choices(bytes(range(97,123)).decode(),k=10)) "".join(random.choice(bytes(range(97,123)).decode()) for _ in range(10)) "".join(random.sample(bytes(range(97,123)).decode(),k=10)) #生成26个字母 "".join(chr(i) for i in range(97,123)) string.ascii_lowercase "".join(bytes(range(97,123)).decode()) #生成随机的10个字母 "".join(random.choices("".join(chr(i) for i in range(97,123)),k=10)) "".join(random.sample(bytes(range(97,123)).decode(),k=10)) "".join(random.choice(string.ascii_lowercase) for i in range(10))
"0001.dfafdedeff"是ID的格式,要求ID格式是点分隔,左边是4位从1开始,后边是10位随机的字母,生成10个
["{:04}.{}".format(i,"".join(random.choice(string.ascii_lowercase) for i in range(10))) for i in range(1,10)]
把如上生成随机的10个字母替换到format第二个参数位置即可。
标签:image 生成 asc span ima ring case byte 开始
原文地址:https://www.cnblogs.com/alrenn/p/12656465.html