Python for Beginners 07: Calling Functions

If you’re completely new to programming, you might not understand the heading: What is “calling functions” supposed to mean? Actually, “calling” is just a technical term for “using“ here. You can think of the existing functions as being dormant somewhere in the memory of the program or in a library. If you want to use them, you need to call them so they appear.

In fact, this lesson is basically just a revision with a more detailed look on a topic you already know, like the previous ones on output and user input. We have used several functions before, for instance print(), input() or type(), but this time we are going to focus on the terminology.

  • When we refer to functions, we say their name, for example print, input or type. Be aware that capital letters matter and change the name.
  • You probably remember from my way of writing functions that they are followed by brackets. What is inside, is called the argument. Depending on the function, it can be one or several variables.
  • What do functions do? Functions take an argument, implement a series of operations and return a result. This is why the result is also called return value.

Time to practice: Use at least 5 functions in Thonny and indicate the name, argument(s) and return value in comments. Hint: I’ve already mentioned three functions above and in the post on data types, you can find some more.

Be aware that only the function print() generates an output, i.e. you can see the return value when you execute the program. For all the other functions, you need to assign them to a variable and then print it in order to see the return value in the console.

This post is based on Chapter 3 of Think Python by Allen B. Downey.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s