2.5.1 Functions and Modules
Python Programming
Functions and modules in Python are key to writing efficient and organized code. Functions allow you to encapsulate reusable blocks of code, while modules help you structure your program by grouping related functions together.
2.5.1.1 Defining and Invoking Functions
Functions are defined using the def keyword, followed by the function name and parentheses which may include parameters. The body of the function contains the code to be executed and must be indented.
python
def function_name (parameters): # code to be executedExample: Define a function to greet a person.
python
def greet(name):
print("As-Salaam-Alaikum"