Integers, floating-point numbers and complex numbers fall under the PythPython numbers category. They are defined as int, float, and complex classes in Python.
We can use the type() function to know which class a variable or a value belongs to. Similarly, the isinstan() function is used to check if an object belongs to a particular class.
a = 5 print(a, "is of type", type(a))
a = 2.0 print(a, "is of type", type(a))
a = 1+2j print(a, "is complex number?", isinstance(1+2j,complex)) Output
5 is of type <class 'int'> 2.0 is of type <class 'float'> (1+2j) is complex number? True
To check the data type of variable in Python, use type() method. Python type() is an inbuilt method that returns the class type of the argument(object) passed as a parameter. You place the variable inside of a type() function, and Python returns the data type.
We can use the type() function to know which class a variable or a value belongs to. Similarly, the isinstan() function is used to check if an object belongs to a particular class.
a = 5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
Output
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True
To check the data type of variable in Python, use type() method. Python type() is an inbuilt method that returns the class type of the argument(object) passed as a parameter. You place the variable inside of a type() function, and Python returns the data type.