print function and unwanted trailing space

candide candide at free.invalid
Sat Aug 31 04:17:23 EDT 2013


What is the equivalent in Python 3 to the following Python 2 code:

# -----------------------------
for i in range(5):
     print i,
# -----------------------------

?

Be careful that the above code doesn't add a trailing space after the 
last number in the list, hence the following Python 3 code isn't 
strictly equivalent:


# -----------------------------
for i in range(5):
     print(i, end=' ')   # <- The last ' ' is unwanted
print()
# -----------------------------



More information about the Python-list mailing list