Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: printing horizontally rather than current default printing

Tags:

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 
like image 994
frazman Avatar asked Dec 08 '11 21:12

frazman


People also ask

Which keyword is used in print () for printing horizontally?

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.

How do you print vertically in Python?

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.

How do I force python to print on the same line?

To print on the same line in Python, add a second argument, end=' ', to the print() function call. print("It's me.")

How do you print a horizontal line in Python?

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 =.


1 Answers

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 
like image 113
unutbu Avatar answered Oct 12 '22 11:10

unutbu