如何在python中打印出类似的内容?
这是我到目前为止所能做的:
for i in range(24):
print("("+str(i)+", "+str(i)+"):",i, end="")
答案 0 :(得分:2)
以下内容:
i = 0
for y in range(0, 500, 125):
for x in range(0, 750, 125):
print('(%3d, %3d): %3d ' % (x, y, i), end='')
i += 1
print()
产生
( 0, 0): 0 (125, 0): 1 (250, 0): 2 (375, 0): 3 (500, 0): 4 (625, 0): 5
( 0, 125): 6 (125, 125): 7 (250, 125): 8 (375, 125): 9 (500, 125): 10 (625, 125): 11
( 0, 250): 12 (125, 250): 13 (250, 250): 14 (375, 250): 15 (500, 250): 16 (625, 250): 17
( 0, 375): 18 (125, 375): 19 (250, 375): 20 (375, 375): 21 (500, 375): 22 (625, 375): 23
或者,使用单个循环:
for i in range(24):
print('(%3d, %3d): %3d ' % (i % 6 * 125, i // 6 * 125, i), end='')
if (i + 1) % 6 == 0:
print()
答案 1 :(得分:0)
from __future__ import print_function
from itertools import count
counter = count()
for i in range(4):
for j in range(6):
print ((j*125,i*125),':',next(counter),end='\t')
print()
您可以使用字符串格式来获得所需文本的对齐方式。