有没有办法写它所以我不必输入+ str(random.choice(string.ascii_uppercase))3次?
strip 1 ''.join([c for c in s if c not in ('!',' ',',',)])
strip2 = strip1 + str(random.choice(string.ascii_uppercase))+ str(random.choice(string.ascii_uppercase))+ str(random.choice(string.ascii_uppercase))
return (strip2)
答案 0 :(得分:1)
使用for loop
strip2 = strip1
for i in range(3):
strip2 += str(random.choice(string.ascii_uppercase))
答案 1 :(得分:0)
list comprehension + range:
strip2 = strip1 + ''join([str(random.choice(string.ascii_uppercase)) for x in range(3)])