Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

The print() function

Three important questions have to be answered as soon as possible:

  1. What is the effect the print() function causes?
    The effect is very useful and very spectacular. The function:
  • takes its arguments (it may accept more than one argument and may also accept less than one argument)
  • converts them into human-readable form if needed (as you may suspect, strings don't require this action, as the string is already readable)
  • and sends the resulting data to the output device (usually the console); in other words, anything you put into the print() function will appear on your screen. 

            No wonder then, that from now on, you'll utilize print() very intensively to see the results of your operations and evaluations. 

      2. What arguments does print() expect? 
           
Any. We'll show you soon that print() is able to operate with virtually all types of data offered by Python. Strings, Numbers, characters, logical values, objects - any of these may be successfully passed to print(). 

      3. What value does the print() function return? 
           None its effect is enough. 

The print() function- instructions

You have already seen a computer program that contains one function invocation. A function invocation is one of many possible kinds of Python instructions. 

Of course, any complex program usually contains many more instructions than one. The question is: how do you couple more than one instruction into the Python code? 

Python's syntax is quite specific in this area. Unlike most programming languages, Python requires that there cannot be more than one instruction in a line. 

A line can be empty (i.e., it may contain no instruction at all) but it must not contain two, three or more instructions. This is strictly prohibited. 

Note: Python makes one exception to this rule - it allows one instruction to spread across more than one line )which may be helpful when your code contains complex constructions). 

Let's expand the code a bit, you can see it in the editor. Run it and note what you see in the console. 

Your Python console should now look like this: 

This is a good opportunity to make some observations:

  • the program invokes the print() function twice, and you can see two separate lines in the console - this means that print() begins its output from a new line each time it starts its execution; you can change this behavior, but you can also use it to your advantage;
  • each print() invocation contains a different string, as its argument and the console content reflects it - this means that the instructions in the code are executed in the same order in which they have been place in the source file; no next instruction is executed until the previous one is completed (there are some exceptions to this rule, but you can ignore them for now) 
  •