11.2. Calling Functions¶
Calling a function is the act of running that function and giving it the information it needs to do its job.
11.2.1. Making a Function Run¶
The general syntax for calling a function is:
You have already become familiar with several Python functions:
- Type conversion functions like
- String and list methods, such as
Every function works in the same way. By typing the function’s name, followed by parentheses, we call the function. This results in an action being carried out.
Sometimes, we include values inside the parentheses. When we do this, the function carries out its action with that data.
The action of the
int function returns the integer value from the given input.
print("Hello, World!") num = int("23") print(num)
Hello, World! 23
As programmers, we do not need to know how Python prints to the console or converts a string to an integer. Instead, we just need to be able to ask Python to do those jobs for us with the data we supply.
Arguments refer to the data values we send to a function. Some functions
do not require arguments inside the parentheses,
If a function requires more than one argument, we separate them with commas:
function_name(argument_1, argument_2, ...)