Key Concepts

Review core concepts you need to learn to master this subject

Functions

# Define a function my_function() with parameter x def my_function(x): return x + 1 # Invoke the function print(my_function(2)) # Output: 3 print(my_function(3 + 5)) # Output: 9

Some tasks need to be performed multiple times within a program. Rather than rewrite the same code in multiple places, a function may be defined using the def keyword. Function definitions may include parameters, providing data input to the function.

Functions may return a value using the return keyword followed by the value to return.