我如何将这些邮政编码字符组合在一起?

时间:2016-10-16 02:06:52

标签: python loops scripting

所以我试图按顺序生成邮政编码,但输出会使每个字符分开,是否有办法将它们组合在一起?

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)

1 个答案:

答案 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))