法1
import stringimport randomcode = ”.join(random.sample((string.digits + string.ascii_lowercase), 4)) #sample组合随机4个print(code)
法2
import randomall_raw_code = [‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’]my_code = []for i in range(4): gen_code = all_raw_code[random.randint(0,len(all_raw_code)-1)] my_code.append(gen_code)print(‘我的提取码:’,”.join(my_code))