Data Types in Python
If you want to start coding in any programming language you have to learn the data types of that programming language. Python is very much rich in it’s data types. There are different data types in Python. Let’s see these different data types in Python:
Category | Data Types | Example |
---|---|---|
Text Type | str | i = “Fahimur Rahman Khan” |
Numeric Types | int
float complex |
x_int = 100
y_float = 100.33 z_complex = 1j |
Sequence Types | list
tuple range |
x_list = [“Minhajur”, “Rahman”, “Khan”]
y_tuple = (“Minhajur”, “Rahman”, “Khan”) z_range = range(100) |
Mapping Type | dict | dist_map = {1 : “Dhaka”, 2 : “Gazipur”} |
Set Types | set
frozenset |
v_set = {“Dhaka”, “Gazipur”, “Jamalpur”, “Rajshahi”}
v_f_set = ({“Dhaka”, “Gazipur”, “Jamalpur”, “Rajshahi”}) |
Boolean Type | bool | i = True |
Binary Types | bytes
bytearray memoryview |
x = b”Great”
y = bytearray(1024) z = memoryview(bytes(1024)) |
To see the data type of a variable write the following code:
a=3.43 print("Data type of variable a is ",type(a))
Result will be:
Data type of variable a is <class 'float'>
In this tutorial, I have shown the different data types in Python. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.