Menu

Output

Printing Multiple Items with Commas

You can give print() several items at once by separating them with commas. Python prints all the items on the same line and adds a single space of its own between each pair. The commas are separators only, so they do not appear in the output.

This is handy when a line is made from separate pieces, such as a label, a team name and a score. Each comma tells Python that another item is coming.

home_team = "Hawks"
home_score = 4
away_team = "Wolves"
away_score = 1
print("Final score:", home_team, home_score, "versus", away_team, away_score)

Output:

Final score: Hawks 4 versus Wolves 1

The score variables hold numbers, but they do not need to be converted to strings first. When the items are separated by commas, print() displays each number as part of the line. It works through the items from left to right. It does not squash the items together with no gap, and it does not add several spaces: there is one space between neighbouring items.

Do not add extra spaces at the ends of the text items to separate them. The comma already supplies one space, so extra spaces would make the gap wider.

Practise this