Answers for "How do you print multiple things on one statement in Python?"

1

How do you print multiple things on one statement in Python?

python 3:

print('Python', 3, 'Rocks')
>>> Python 3 Rocks

with sep:
print('Python', 3, 'Rocks', sep='|')
>>> Python|3|Rocks

(sep=' ' is added by default, so to print space between values, 
sep is not necessary)

with end:
by default, end="n" is appended, so to print a new line after, end is not
necessary. However you can replace n with something else.

print('Python', 3, 'Rocks', end='*')
print('I love Python')
>>> Python 3 Rocks*I love Python


python 2:
print 'Python', 2, 'Rocks'
>>> Python 2 Rocks

with sep:
from __future__ import print_function
print("Python","Rocks", sep="|")
>>> Python|3|Rocks

similar to end:
  just add a comma after the first print statement
print 'Python', 2, 'Rocks', '*',
print 'I love Python'
>>> Python 3 Rocks*I love Python
Posted by: Guest on January-29-2022

Code answers related to "How do you print multiple things on one statement in Python?"

Python Answers by Framework

Browse Popular Code Answers by Language