Wednesday, 4 July 2012

Python – Variable Types


Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.

Assigning values to Variables:

Python variables do not have to be explicitly declared to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables.
The operand to the left of the = operator is the name of the variable, and the operand to the right of the = operator is the value stored in the variable. For example:

#!/usr/bin/python
Counter = 100             #An integer assignment.
Miles = 1000.0                        #A Floating point.
Name = “John”           #A String
Print Counter
Print Miles
Print Name

This will produce following result:

100
1000.0
John

No comments:

Post a Comment