Introduction to Data types
In computer science and computer programming, a data type or simply type is a classification of data which tells the compiler or interpreter how the programmer intends to use the data. Most programming languages support various types of data, for example: real, integer or Boolean. A data type provides a set of values from which an expression (i.e. variable, function…) may take its values. This data type defines the operations that can be done on the data, the meaning of the data, and the way values of that type can be stored. A type of value from which an expression may take its value
Variables
Variables are nothing but reserved memory locations to store values. It means that when you create a variable, you reserve some space in the memory.
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.
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 = 100
miles = 1000.0
name = “John”
print (counter)
print (miles)
print (name)
Here, 100, 1000.0 and “John” are the values assigned to counter, miles, and name variables, respectively. This produces the following result –
100
1000.0
John
Multiple Assignment
Python allows you to assign a single value to several variables simultaneously.
For example-
a=b=c=1
Here, an integer object is created with the value 1, and all the three variables are assigned to the same memory location. You can also assign multiple objects to multiple variables.
For example-
a, b, c = 1, 2, “john”
Here, two integer objects with values 1 and 2 are assigned to the variables a and b respectively, and one string object with the value “john” is assigned to the variable c.