所以我试图按顺序生成邮政编码,但输出会使每个字符分开,是否有办法将它们组合在一起?
for first in range(10):
for second in range(65,91):
for third in range(10):
for fourth in range(10):
for fifth in range(65,91):
for sixth in range(10):
print(first,chr(second),third,fourth,chr(fifth),sixth)
答案 0 :(得分:0)
使用.format
例如:
a = 10
b = 11
'{}{}'.format(a,b)
输出:
1011
这样:
for first in range(10):
for second in range(65,91):
for third in range(10):
for fourth in range(10):
for fifth in range(65,91):
for sixth in range(10):
print('{}{}{}{}{}{}'.format(first,chr(second),third,fourth,chr(fifth),sixth))