WHAT ARE DATA TYPES IN PYTHON?

DATA TYPES IN PYTHON.
Data means information and we all know categories refer to different forms. So, datatypes are the information in altered forms. The altered forms refer to integer, string, float..etc. The different data types are store in a flexible. In python, it is not essential to define data types the reason behind it is that data types are declared suddenly as values are assigned to the variables. But in another program writing The different data types are given below with samples:

Text Type:: str
Numeric Types:: int, float, complex
Sequence Types:: list, tuple, range
Mapping Type:: dict
Set Types:: set, frozenset
Boolean Type:: bool
BinaryTypes:: bytes, bytearray,memoryview
Int:
x = 50
X = -7

it is an integer datatype. This can also be printed as x=int(5) to set data as an integer. This can be positive or negative figure, it comprises whole number without decimal points on it with unlimeted length.

Float:
x=5.0
X= – 0.48
x=8e9

this is float type which means point importance.

String:
x=”I love Python”
x= ‘I love Python’

this is an string datatype. string data type must be printed inside the double or single quote. For multiline string it can be printed as
x=”””I love Python
I love Python
I love Python””” (with double-quote) or

x=”’ I love Python
I love Python
I love Python”’ (with a single-quote)
Complex:
x=5j+1 this is a complex data type.
other data types will be deliberated later on their specific topic.

GETTING DATA TYPES.
To get the datatype you can write a lettering as below:

print(type()) or you can see the picture below:
In the above picture, we can see the output as <class ‘int’> which means the datatype store in a adjustable is an integer type.
Conversion Of Data Types
In python, we can transform one data type to other. We can convert an number to float and float to integer. But complex cannot be diverse to others.
#converting from int to float
x=20
y=float(x)
print(y)
print(type(x))
print(type(y))
in the code above first, it will store value 20 to x and in y it will change the integer value of x to float and store to y. once we print y we will get the production as 20.00. Also, when we type print it will provide the datatype of the variable. Then, The x and y are variables.

Random Number
Python organizes not have a random() function to make a arbitrary number, but Python has a built-in component called random that can be charity to make random numbers or it will print random figures between any numbers.
#converting from int to float
import random
print (random.randrange(1,5))

It will print random records as output between 1 and 5.
For More Details About Python Online Training Contact us @ +91 9550102466

Comments are closed