First steps pure Python: function calls

First steps pure Python: function calls#

There are built-in functions and developers can of course define their own functions.

Here, we will just see how functions are called since we will need that to start the course.

Some functions have only side effects but do not return anything. A typical example is the print function, which can be used like this:

print("hello")
hello

Other functions return a result, for example the round function:

round(1.2)
1

Here, we see the result because we are in IPython, which has this behaviour to show a representation of the object produced by the last line of a cell.

However, in a Python file round(1.2) would just compute the result and it would be unusable.

It’s common to store the result in a variable:

my_var = round(1.2)

which can then be used:

my_var
1
my_var + 1
2