-2

i have a list as:

one = [(1, 2), (3, 4)]
for o in one:
    print o
(1, 2)
(3, 4)

i need to print (1, 2) and (3, 4) in the same line

for o in one:
    print o
(1, 2) (3, 4)
Gianni Spear
  • 7,033
  • 22
  • 82
  • 131

1 Answers1

4

In python2, it would be done as follows:

one = [(1, 2), (3, 4)]
for o in one:
    print o,      #added the ,
print      #and an optional print() to ensure that anything afterwords prints on a separate line

In python3, you need slight modifications since print becomes a function:

one = [(1, 2), (3, 4)]
for o in one:
    print(o, end=' ')
print()    #and an optional print() to ensure that anything afterwords prints on a separate line

Alternatively (thanks to @user2357112 for the suggestion)

one = [(1, 2), (3, 4)]
print(*one)

[OUTPUT]  from all
(1, 2)(3, 4)
sshashank124
  • 31,495
  • 9
  • 67
  • 76