Learning Outcomes:
Upon successful completion of this lesson, you will be able to:
A function is a group of statements that exists within a program for the purpose of performing a specific task. It provides reusable codes to reduce development time. For example, input() can be called when we want to get input from user and print() can be called to display output of a program. We said that input() and print() are reusable.
e-lecture videos:
Types of Function
There are void functions and value-returning functions:
Defining and Calling a Function
We define a function by using def keyword.
# This is a function named hello
def hello():
print("Hello World")
# Call the function
hello()
# First function, main() calls hello() function
def main():
print("Calling the hello function ...")
hello()
print("End of main function")
# hello() function is defined here
def hello():
print("Hello World")
# Call main() function
main()