The structure of a Python program is similar to that used in other languages but with several important differences. Consider the following program which computes and prints the sum of the first 100 positive integers.
Python, unlike C, C++, and Java, does not use a main
routine as the entry point for execution. Instead, like Perl, Ruby, and Php, the first executable statement at the top-most or global level is the first statement executed. In the sum.py
example, the statement
NUM_VALUES = 100
is the first statement executed. Execution then continues to the next statement and then the next. Functions and classes can also be defined within a Python program. But they are only executed, when the function or a related method is invoked.
Several important differences include: