How to check data type in Python

In this article, you’ll see how to check data type in Python. To find the data type of a variable in Python use the built-in function type(variable). I highly recommend you get the “Python Crash Course Book” to learn Python.

a = 10
print(type(a))

b = 5.3
print(type(b))

c = "Ai Hints"
print(type(c))

d = 5j+8
print(type(d))

e = ["X", 5, 10, "Y"]
print(type(e))

f = (5, 7, "X", 8)
print(type(f))

g = {"A":[1, 2, 3], "B":[5, 10, 15], "C":[50, 100, 20.5]}
print(type(g))

h = {'X', 'Y', 'Z', 5}
print(type(h))

Output:

<class 'int'>
<class 'float'>
<class 'str'>
<class 'complex'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'set'>

Leave a Comment

Your email address will not be published.