Skip to main content

Section 6.1 Function calls

In the context of programming, a function is a named sequence of statements that performs a computation, gets input, or produces output. We have been using functions all along in this course. We do a function call by giving the name of the function and, in parentheses, any extra information the function needs to do its work.
In fact, we have been making function calls in almost all the programs we’ve written so far! Take a look at this short program:
There are three function calls in this program:
  • The first one is to a function named input. The expression in the parentheses is called the argument of the function. The argument is a value or variable that we are passing into the function for it to use. The input function uses the argument to display the prompt for the user. The result, for the input function, is whatever string the user typed in at the keyboard.
  • The next call is to a function named float, which takes a string or integer as its argument and gives back a number with decimal places as its result. We will talk about it more in Section 6.3. Its argument is the num_str variable.
  • The last call is to a function named print. The print function takes zero or more items as its argument(s). Unlike the other two functions, which give back a result that we can assign to a variable, the print function displays its arguments on the screen and returns the special value None.
It is common to say that a function takes an argument and returns a result. The result is called the return value.
All of the functions you have used so far are built-in functions. The creators of Python wrote these functions to solve common—and important—problems. These functions are included in Python for us to use without needing to provide the function definition ourselves.

Checkpoint 6.1.1.

Checkpoint 6.1.2.

Checkpoint 6.1.3.

Q-4: A _________ is a named sequence of statements that performs a computation.
Later on in this chapter, you will learn how to write your own functions—and why it’s a good thing to learn. First, though, let’s look at some more built-in Python functions.