Like other programming languages python has standard data types, those are
- Numbers
- Strings
- List
- Tuple
- Dictionary
In python, there is no explicit declaration of variables. As we know a variable is a reserved memory location to store specified data values. When a variable is created it reserves a space in memory with the memory name as a variable. As per the data type assigned data to the variable memory space is resereved and what is stored in that memory space.
Generally in C or Java etc languages an intereger variable can be declared as
int A =10;
Variable A is of integer type and value is 10.
But, in python the variable is declared as
A = 10;
Python interepreter automatically treated a is a variable of integer type based on the assigned value of that variable.
A = 10 // A is integer type
B = 10.25 // B is floating type
C =’a’ // C is character type
D = “String” //D is of type String
In python, single quote and double quotes are used for declaring string or characters. Anything between single or double quotes can be treated as data type String.
To know the data type of variable in python use type().
Syntax : type(variable)
Print(type(A)) -> it prints A is of type integer.
See the above image for variable declaration and its type.
>>> A = 10
>>> B = 10.25
>>> C = 'a'
>>> D = "String"
>>> print(A)
10
>>> print(type(A))
<class 'int'>
>>> print(B)
10.25
>>> print(type(B))
<class 'float'>
>>> print(C)
a
>>> print(type(C))
<class 'str'>
>>> print(D)
String
>>> print(type(D))
<class 'str'>
>>>