[Type text]
What are variables in Python?
A Python variable is a reserved memory location to store values. In other words,
a variable in a python program gives data to the computer for processing. Every
value in Python has a datatype. Different data types in Python are Numbers,
List, Tuple, Strings, Dictionary, etc.
Based on the data type of a variable, the interpreter allocates memory and
decides what
can be stored in the reserved memory. Therefore, by assigning different data
types to the
variables, you can store integers, decimals or characters in these variables.
Assigning Values to Variables
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
counter = 100 # An integer assignment
miles = 1000.0 # A floating point
name = "John" # A string
print (counter)
print (miles)
print (name)
output
100
1000.0
John
Multiple Assignment
Python allows you to assign a single value to several variables simultaneously.
a= b = c = 1
a, b, c = 1, 2, "john"
Standard Data Types
[Type text]
The data stored in memory can be of many types. For example, a person's age is
stored
as a numeric value and his or her address is stored as alphanumeric characters.
Python
has various standard data types that are used to define the operations possible
on them
and the storage method for each of them.
Python has five standard data types-
Numbers
String
List
Tuple
Dictionary
Python Numbers
Number data types store numeric values. Number objects are created when you
assign a
value to them. For examplevar1
=1
var2 = 10
You can also delete the reference to a number object by using the del
statement. The
syntax of the del statement is −
del var1[,var2[,var3[....,varN]]]]
You can delete a single object or multiple objects by using the del statement.
For exampledel
var
del var_a, var_b
Python supports three different numerical types −
int (signed integers)
float (floating point real values)
complex (complex numbers)
[Type text]
All integers in Python 3 are represented as long integers. Hence, there is no
separate
number type as long.