Assigning Values to Variables in the Python
Categories: Python
Python variables do not need explicit declaration 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 −
counter = 10 # An integer assignment
miles = 100.0 # A floating point
name = "Priya" # A string
print counter
print miles
print name
Output
Here, 10, 100.0 and "Priya" are the values assigned to counter, miles, and name variables, respectively. This produces the following result −
10
100.0
Priya