Python: Print Without Newline

By Xah Lee. Date: .

Print Without Newline

print( "a", "b", sep=",", end=",")
print( "c")
# prints
# a,b,c

Python 2, Print Without Newline

To print without the newline char added at the end, add a comma.

# -*- coding: utf-8 -*-
# python 2

# suppress printing newline
print "rabbit",
print "tiger"

# prints
# rabbit tiger

Or, use sys.stdout.write().

# -*- coding: utf-8 -*-
# python 2

import sys
sys.stdout.write("rabbit")
sys.stdout.write("tiger")

# prints
# rabbittiger

Python, String