Python 3 - First Program (02)

To download Python, visit www.python.org

 

Writing a Python Program

Python programs must be written with a particular structure. The syntax must be correct, or the interpreter will generate error messages and not execute the program. This section introduces Python by providing a simple example program. Listing 1.1 (simple.py) is one of the simplest Python programs that does something:

print("This is a simple Python program")

Note: The small numbers that appear to the left of the box containing the Python code are not part of the program; the numbers are shown to allow us to easily reference a specific line in the code if necessary. We will consider two ways in which we can run Listing 1.1 (simple.py):

  1. enter
the program directly into IDLE’s interactive shell and 

  2. enter the program into IDLE’s editor, save it, and run it. 

print("This is a simple Python program")

  This is a Python statement. A statement is a command that the interpreter executes. This statement prints the message This is a simple Python program on the screen. A statement is the fundamental unit of execution in a Python program. Statements may be grouped into larger chunks called blocks, and blocks can make up more complex statements. Higher-order constructs such as functions and methods are composed of blocks. The statement makes use of a built in function named print. Python has a variety of different kinds of statements that may be used to build programs, and the chapters that follow explore these various kinds of statements.

If you have any doubts, Please Comment below,......



Subscribe to receive free email updates:

Related Posts :

0 Response to "Python 3 - First Program (02)"

Post a Comment