I was wondering if we can print like row-wise in python.
Basically I have a loop which might go on million times and I am printing out some strategic counts in that loop
Use this code for your print
print(x,end="")
a=int(input("RangeFinal "))
print("Prime Numbers in the range")
for n in range(2, a):
p=0
for x in range(2, n):
if n % x == 0:
break
else:
if(p==0):
print(n,end=' ')
p=1
Answer
RangeFinal 19
Prime Numbers in the range
3 5 7 9 11 13 15 17
If you add comma at the end it should work for you.
>>> def test():
... print 1,
... print 2,
...
>>> test()
1 2
my_list = ['keyboard', 'mouse', 'led', 'monitor', 'headphones', 'dvd']
for i in xrange(0, len(my_list), 4):
print '\t'.join(my_list[i:i+4])
In Python2:
data = [3, 4]
for x in data:
print x, # notice the comma at the end of the line
or in Python3:
for x in data:
print(x, end=' ')
prints
3 4
You can add a comma after your call to print to avoid the newline:
print 3,
print 4,
# produces 3 4