From Python for Java Programmers

Introduction: Program Execution

Page Contents (hide)

Python has two modes for program execution: interpreted (or normal mode) and interactive.

Interpreted Mode

A Python program is constructed as a text file containing the instructions to be executed. The following is a simple example of a Python program.

# Classic hello world program in Python.

print "Hello World"
print "How are you today?"
 

Main Routine

Every program must have a unique starting point; a first statement to be executed. In Java, C and C++, the starting point is the first statement within the main() routine.

In Python, the first statement to be executed, is the first statement in the file at the global level (outside of all functions and methods). In the above example, the first “print” statement will be the first statement executed.

Execution

At the command line:

python mypgm.py

Under UNIX,

#!/usr/bin/python
%> chmod +x mypgm.py
%> mypgm.py

Interactive Mode

Retrieved from http://python4java.necaise.org/Introduction/ProgramExecution
Page last modified on May 19, 2010, at 11:23 AM