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.. so it would be really cool if I can print like row-wise
print x # currently gives # 3 # 4 #.. and so on
and i am looking something like
print x # 3 4
If you want to print horizontally you can use \t it is used for horizontal tab or else you can simply leave space or else you can write %(number of space you want to leave)d for example %5d.
The naive method can be used to print the list vertically vis. using the loops and printing each index element of each list successively will help us achieve this task. Using zip function, we map the elements at respective index to one other and after that print each of them.
To print on the same line in Python, add a second argument, end=' ', to the print() function call. print("It's me.")
Here the ASCII value u'\u2500' relates to hyphen without spaces at start and end. The \u specifies the following string is in extended ASCII form and 2500 denotes the ─ symbol. U+2550 is a double stroke ═ like =.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With