How to find data type in Python
In python, you can find the data type using the built in function type()
. Since everything is an object in Python, data types are actually classes and variables are instance (object) of these classes.
We can use the type()
function to know which class a variable or a value belongs to.
a = 5 print("Type of a is", type(a)) b = 4.3 print("Type of b is", type(b)) c = 'Santa' print("Type of c is", type(c)) d = [1, 4, 2, 5] print("Type of d is", type(d)) e = ('a', 'b', 2) print("Type of e is", type(e)) f = {1:'one', 2:'two'} print("Type of f is", type(f))
Output:
Type of a is <class 'int'> Type of b is <class 'float'> Type of c is <class 'str'> Type of d is <class 'list'> Type of e is <class 'tuple'> Type of f is <class 'dict'>
Subscribe
Login
Please login to comment
0 Discussion