Python 格式化循环打印
我使用以下代码通过运行循环创建多行数据:Python 格式化循环打印,python,loops,data-structures,format,Python,Loops,Data Structures,Format,我使用以下代码通过运行循环创建多行数据: 导入数学 x=65 y=123 curRow=0 curCol=0 maxCol=2 行=math.ceil((y-x)/maxCol) 当前
导入数学
x=65
y=123
curRow=0
curCol=0
maxCol=2
行=math.ceil((y-x)/maxCol)
当前<行时:
curCol=0
printRow=“”
而curCol=100:
char=(chr(x))
numb=ord(字符)
hexi=格式(ord(字符),'x')
printRow+=str(numb).ljust(1)+hexi.rjust(7)+str(char).rjust(10)+''.rjust(10)
x+=1
curCol+=1
打印(打印行)
curRow+=1
将9替换为8:
printRow += (str(numb)).ljust(1) + hexi.rjust(8) + str(char).rjust(10) + ''.rjust(10)
你给了错误的宽度,当x>100时,宽度从2变为3,但是
hexi.rjust
你从9变为7。您可以指定一个更高的最小宽度,这样看起来很漂亮。像这样:
printRow+=(str(numb)).ljust(4)+hexi.rjust(8)+str(char).rjust(10)+''.rjust(10)