我怎样才能让Python在每一行输出x数字? [英] How can I let Python output x numbers on every line?
本文介绍了我怎样才能让Python在每一行输出x数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我希望它在每一行输出4个值:
例如:在范围内(12):
print(i,end ='')
这将在一行打印但是我怎么能让python在第四次输出后跳转到下一行呢?
什么我试过了:
i尝试最小化空闲屏幕
if i want it to output 4 values on every line:
example: for in range(12):
print(i,end=' ')
this will print on one line but how can i let the python jump to the next line after the 4th output?
What I have tried:
i tried minimizing the idle screen
推荐答案
Python不会为你做这件事。您必须自己打印每个值,一次一个。每次打印一个值时,都会增加一个计数器。当该计数器达到4时,转到下一行并重置计数器。
Python won't do this for you. You have to print each value, one at a time, yourself. Each time you print a value you increment a counter. When that counter reaches 4, go to the next line and reset the counter.
for x in range(1,13,4):
for y in range(x, x+4):
print(y, end=", ")
print("")
[edit]
一个稍微整洁的版本:
[edit]
A slightly neater version:
for x in range(1,13,4):
for y in range(x, x+3):
print(y, end=", ")
print(y+1)
[/ edit]
[/edit]
这篇关于我怎样才能让Python在每一行输出x数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文