Professional Documents
Culture Documents
Computer Programming ENEE 101: Lec#13 (Functions Part 2)
Computer Programming ENEE 101: Lec#13 (Functions Part 2)
ENEE 101
Lec#13 (Functions part 2)
Department of Electrical and Electronic Engineering
University of Jeddah 1
The main Function And Its Use
• Many languages, such as C, C++, Java, and several others, define a special function that must
be called main() that the operating system automatically calls when it executes the program.
• This function is often called the entry point because it is where the execution enter (starts)
the program.
• By contrast, Python does not have a special function that serves as the entry point to a
script. You can give the entry point function in a Python script any name you want!
• Although Python does not assign any significance to a function named main(), the best
practice is to name the entry point function main() anyways.
• This can help other programmers to know the starting point of your script.
Ref: https://realpython.com/python-main-function/ 2
Using main Function: Example-1 (finding sum)
4
Transfer of Control (Flow of Program with main function)
Entry
Point
5
Functions with/without Return Values
• A function does not have • Instead, when using return, the retuned value
to return a value. can be saved in a variable for later usage.
6
Q/A
• Show the output of the following codes:
8
Returning Multiple Values