letters = list(string.ascii_letters)
for i in letters:
print(i*5)
我的输出:
aaaaa
bbbbb
ccccc
ddddd
eeeee
fffff
ggggg
hhhhh
......
正确的输出:
['aaaaa', 'bbbbb', 'ccccc', 'ddddd', 'eeeee', 'fffff', 'ggggg', 'hhhhh', 'iiiii', 'jjjjj', 'kkkkk', 'lllll', 'mmmmm', 'nnnnn', 'ooooo', 'ppppp', 'qqqqq', 'rrrrr', 'sssss', 'ttttt', 'uuuuu', 'vvvvv', 'wwwww', 'xxxxx', 'yyyyy', 'zzzzz', 'AAAAA', 'BBBBB', 'CCCCC', 'DDDDD', 'EEEEE', 'FFFFF', 'GGGGG', 'HHHHH', 'IIIII', 'JJJJJ', 'KKKKK', 'LLLLL', 'MMMMM', 'NNNNN', 'OOOOO', 'PPPPP', 'QQQQQ', 'RRRRR', 'SSSSS', 'TTTTT', 'UUUUU', 'VVVVV', 'WWWWW', 'XXXXX', 'YYYYY', 'ZZZZZ']
答案 0 :(得分:0)
您想要的输出是一个列表,但您正在打印的是生成它们时的单个元素。首先生成列表然后打印它。 以下是您可以遵循的代码段。
letters = list(string.ascii_letters)
l = [i*5 for i in letters]
print l
您还可以合并前两行
l = [i*5 for i in string.ascii_letters]