Print

New:

  • function print

In Value we said that the interpreter does not output values unless the source code contains a special instruction. In the past, such an instruction was implemented as a command print. Commands are core components of the programming language, they work and interact with other code differently than functions.

That particular command is no longer available in modern Python. The function print plays its role. Being a function, it utilizes arguments passed to it in a call. print outputs its argument in the text form. Let's use it to view the value generated by pow:

print(pow(3, 2))
9

A function call pow(3, 2) was used as an argument inside of the print call. When print call happens, call pow(3, 2) is already perceived as the result of raising 32 by the interpreter. We can achieve the same output by manually providing value 9 as the argument:

print(9)
9

Or by using a whole mathematical operation as argument:

print(3 + 3 + 3)
9
print(3 * 3)
9

Note how the interpreter sort of loses information written in the source code. Function calls and different math operations all reduced to a single value. This isn't just due to printing, but rather due the interpreting that happens when you run your code. The source code and the results of running it are unbalanced in this way, so you can't judge what's going on in the code by looking at the results only.

The historic printing command had one objective — to output any value that can exist in a Python program. Which means handling any type, be it a string, number or something else. Function print, which replaced the command, is therefore designed to accept and display arguments of any type. So, let's display our pasta:

print("Pasta Carbonara")
Pasta Carbonara

Experiment with print below, try printing numbers, results of pow and random strings. Within Repl.it the output is displayed in the console.