Output
Output is data a program sends out: information for whoever is using it, such as text on the screen, numbers in a console window or a sound from the speakers. It is how a program reports back what it has done, so almost every program you write will produce some.
In Python 3, output is produced with the built-in print function. Its name is written in lower case and is followed by a pair of brackets holding the item or items you want to output. Whatever sits between those brackets is what reaches the screen.
A print call can output a string of text, a plain number, a variable (the value it currently holds is output), or a calculation, where the result is sent to the screen rather than the calculation itself. One function therefore copes with every kind of output you need.
Each print call starts a new line. Once it has sent its item to the screen, the next output begins on the line below, so calls never run into each other, however many you write in a row.
Brackets with nothing between them, print(), output no characters but still move to the next line, leaving a blank line behind. You use it to space out output so it is easier to read.
Because each print call starts a fresh line, you can print a pattern, picture or table of characters row by row, using one print call for every row. The characters you place in the brackets appear exactly in that row, so you build the pattern from the top downwards and never need to type a line break yourself.
team_points = 31
print("Sports day results") # first line of output
print() # empty brackets: a blank line
print("Points scored:")
print(team_points)
print(team_points + 9)Output:
Sports day results
Points scored:
31
40
Five calls give five lines, and the empty call in the middle leaves a deliberate gap between the heading and the scores beneath it.
OCR GCSE Computer Science · Output