Python by Swaroop C H - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Objects

Remember, Python refers to anything used in a program as an object. This is meant in the generic sense. Instead of saying 'the something', we say 'the object'.

Note for Object Oriented Programming users

Python is strongly object-oriented in the sense that everything is an object including numbers, strings and even functions.

 

We will now see how to use variables along with literal constants. Save the following example and run the program.

How to write Python programs

Henceforth, the standard procedure to save and run a Python program is as follows:

1. Open your favorite editor.
2. Enter the program code given in the example.

3. Save it as a file with the filename mentioned in the comment. I follow the convention of having all Python programs saved with the extension.py.

 

4. Run the interpreter with the command pythonprogram.py or use IDLE to run the programs. You can also use the executable method as explained earlier.

Example 4.1. Using Variables and Literal constants

# Filename : var.py

i = 5
print i
i = i + 1
print i

s = '''This is a multi-line string. This is the second line.'''
print s