In general, Data Types specifies what type of data will be stored in variables. Variables can hold values of different data types. Python is a dynamically typed or loosely typed language, hence we need not define the type of the variable while declaring it. The interpreter implicitly binds the value with its type.
I.e. In loosely typed language no need to specify the type of variable because the variable automatically changes it's datatype based on assigned value.
Python provides the type() function which enables us to check the type of the variable.
Python provides following standard data types, those are
Number stores numeric values. Python creates Number type variable when a number is assigned to a variable.
There are three numeric types in Python:
Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
format:a = 10
b = -12
c = 123456789
Float or "floating point number" is a number, positive or negative, containing one or more decimals.
format:X = 1.0
Y = 12.3
Z = -13.4
Complex numbers are written with a "j" as the imaginary part.
format:A = 2+5j
B = -3+4j
C = -6j
a = 10
b = 10.5
c = 2.14j
print("Datatype of Variable a :",type(a))
print("Datatype of Variable b :",type(b))
print("Datatype of Variable c :",type(c))
Datatype of Variable a : <class ‘int’>
Datatype of Variable b : <class ‘float’>
Datatype of Variable c : <class ‘complex’>
The string can be defined as the sequence of characters represented in the quotation marks. In python, we can use single, double, or triple quotes to define a string.
In the case of string handling, the operator + is used to concatenate two strings as the operation "hello"+" python" returns "hello python".
S1='Welcome'
S2="to Python"
S3='''world'''
a = "Welcome" #using double quotes
b ='Python' #using single quotes
c = '''World''' #using triple quotes
print("Datatype of Variable a :",type(a))
print(a+b) #to concatenate two strings
Datatype of Variable a : <class ‘str’>
Welcome Python