Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Arguments | What is Function in Python?
Python Functions Tutorial
course content

Contenido del Curso

Python Functions Tutorial

Python Functions Tutorial

1. What is Function in Python?
2. Positional and Optional Arguments
3. Arbitrary Arguments
4. Function Return Value Specification
5. Recursion and Lambda Functions

Arguments

In Python, function arguments are the inputs you give to a function when you call it. They let you provide data or values that the function can work with. These arguments can be individual values or objects like lists, tuples, dictionaries, or custom objects.

For instance, when we use the print() function, we provide a string as an argument. Here's another example:

Assume that we want to write the function that calculates the sum of two different numbers and prints the result. To do it we have to pass these two numbers to the function. We have to do it using () brackets.

123456789
# Specify two arguments of the function def sum_of_two_numbers(num_1, num_2): # Use arguments to calculate sum result = num_1 + num_2 # Print the result print(f'Sum of two numbers is {result}') # Call the function sum_of_two_numbers(2, 10)
copy

Note

You may noticed that we use letter f at the beginning of the string as the argument of print() function. Such construction is called f-string. In Python source code, an f-string is a literal string, prefixed with f , which contains expressions inside braces.

We have passed num_1 and num_2 as an arguments of the function and then used them to calculate the sum. We can set an arbitrary number of function arguments. Next, you will solve a problem with 4 function arguments.
Now let's consider an example when we use a list as an argument of the function:

123456789101112131415
# Define the function `calculate_list_sum` def calculate_list_sum(list): # Initialize the total sum to 0 total = 0 # Iterate through each number in the list for num in list: # Add the current number to the total sum total += num # Print the total sum print(total) # Create a list of numbers my_list = [1, 2, 3, 4, 5] # Call the function calculate_list_sum(my_list)
copy

Tarea

Assume that you have to calculate perimeter of the triangle with sides a, b and c. Write the function with calculates perimeter and prints it in console.

Tarea

Assume that you have to calculate perimeter of the triangle with sides a, b and c. Write the function with calculates perimeter and prints it in console.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 3
toggle bottom row

Arguments

In Python, function arguments are the inputs you give to a function when you call it. They let you provide data or values that the function can work with. These arguments can be individual values or objects like lists, tuples, dictionaries, or custom objects.

For instance, when we use the print() function, we provide a string as an argument. Here's another example:

Assume that we want to write the function that calculates the sum of two different numbers and prints the result. To do it we have to pass these two numbers to the function. We have to do it using () brackets.

123456789
# Specify two arguments of the function def sum_of_two_numbers(num_1, num_2): # Use arguments to calculate sum result = num_1 + num_2 # Print the result print(f'Sum of two numbers is {result}') # Call the function sum_of_two_numbers(2, 10)
copy

Note

You may noticed that we use letter f at the beginning of the string as the argument of print() function. Such construction is called f-string. In Python source code, an f-string is a literal string, prefixed with f , which contains expressions inside braces.

We have passed num_1 and num_2 as an arguments of the function and then used them to calculate the sum. We can set an arbitrary number of function arguments. Next, you will solve a problem with 4 function arguments.
Now let's consider an example when we use a list as an argument of the function:

123456789101112131415
# Define the function `calculate_list_sum` def calculate_list_sum(list): # Initialize the total sum to 0 total = 0 # Iterate through each number in the list for num in list: # Add the current number to the total sum total += num # Print the total sum print(total) # Create a list of numbers my_list = [1, 2, 3, 4, 5] # Call the function calculate_list_sum(my_list)
copy

Tarea

Assume that you have to calculate perimeter of the triangle with sides a, b and c. Write the function with calculates perimeter and prints it in console.

Tarea

Assume that you have to calculate perimeter of the triangle with sides a, b and c. Write the function with calculates perimeter and prints it in console.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 1. Capítulo 3
toggle bottom row

Arguments

In Python, function arguments are the inputs you give to a function when you call it. They let you provide data or values that the function can work with. These arguments can be individual values or objects like lists, tuples, dictionaries, or custom objects.

For instance, when we use the print() function, we provide a string as an argument. Here's another example:

Assume that we want to write the function that calculates the sum of two different numbers and prints the result. To do it we have to pass these two numbers to the function. We have to do it using () brackets.

123456789
# Specify two arguments of the function def sum_of_two_numbers(num_1, num_2): # Use arguments to calculate sum result = num_1 + num_2 # Print the result print(f'Sum of two numbers is {result}') # Call the function sum_of_two_numbers(2, 10)
copy

Note

You may noticed that we use letter f at the beginning of the string as the argument of print() function. Such construction is called f-string. In Python source code, an f-string is a literal string, prefixed with f , which contains expressions inside braces.

We have passed num_1 and num_2 as an arguments of the function and then used them to calculate the sum. We can set an arbitrary number of function arguments. Next, you will solve a problem with 4 function arguments.
Now let's consider an example when we use a list as an argument of the function:

123456789101112131415
# Define the function `calculate_list_sum` def calculate_list_sum(list): # Initialize the total sum to 0 total = 0 # Iterate through each number in the list for num in list: # Add the current number to the total sum total += num # Print the total sum print(total) # Create a list of numbers my_list = [1, 2, 3, 4, 5] # Call the function calculate_list_sum(my_list)
copy

Tarea

Assume that you have to calculate perimeter of the triangle with sides a, b and c. Write the function with calculates perimeter and prints it in console.

Tarea

Assume that you have to calculate perimeter of the triangle with sides a, b and c. Write the function with calculates perimeter and prints it in console.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

In Python, function arguments are the inputs you give to a function when you call it. They let you provide data or values that the function can work with. These arguments can be individual values or objects like lists, tuples, dictionaries, or custom objects.

For instance, when we use the print() function, we provide a string as an argument. Here's another example:

Assume that we want to write the function that calculates the sum of two different numbers and prints the result. To do it we have to pass these two numbers to the function. We have to do it using () brackets.

123456789
# Specify two arguments of the function def sum_of_two_numbers(num_1, num_2): # Use arguments to calculate sum result = num_1 + num_2 # Print the result print(f'Sum of two numbers is {result}') # Call the function sum_of_two_numbers(2, 10)
copy

Note

You may noticed that we use letter f at the beginning of the string as the argument of print() function. Such construction is called f-string. In Python source code, an f-string is a literal string, prefixed with f , which contains expressions inside braces.

We have passed num_1 and num_2 as an arguments of the function and then used them to calculate the sum. We can set an arbitrary number of function arguments. Next, you will solve a problem with 4 function arguments.
Now let's consider an example when we use a list as an argument of the function:

123456789101112131415
# Define the function `calculate_list_sum` def calculate_list_sum(list): # Initialize the total sum to 0 total = 0 # Iterate through each number in the list for num in list: # Add the current number to the total sum total += num # Print the total sum print(total) # Create a list of numbers my_list = [1, 2, 3, 4, 5] # Call the function calculate_list_sum(my_list)
copy

Tarea

Assume that you have to calculate perimeter of the triangle with sides a, b and c. Write the function with calculates perimeter and prints it in console.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 1. Capítulo 3
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt