I read that to suppress the newline after a print statement you can put a comma after the text. The example here looks like Python 2. How can it be done in Python 3?
For example:
for item in [1,2,3,4]:
print(item, " ")
What needs to change so that it prints them on the same line?
The question asks: “How can it be done in Python 3?“
Use this construct with Python 3.x:
This will generate:
See this Python doc for more information:
—
Aside:
in addition, the
print()function also offers thesepparameter that lets one specify how individual items to be printed should be separated. E.g.,