To print the variable type of a variable in Python, you can use the type() function to get the type and print it with print().
a = 1
b = "string"
c = [0, 1, 2]
d = (0, 1, 2)
e = {"key":"value"}
f = 1.0
g = {"set"}
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))
print(type(g))
#Output:
<class 'int'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'float'>
<class 'set'>
When working with different objects in Python, the ability to check the type of your variables and objects easily is very important.
In Python, you can easily get the variable type and print it.
type() is a built-in function that helps you find the class type of the given variable.
To print the variable type of a variable in Python, you can use the type() function to get the type and print it with print().
Below shows you how to print the variable type of different objects in Python.
a = 1
b = "string"
c = [0, 1, 2]
d = (0, 1, 2)
e = {"key":"value"}
f = 1.0
g = {"set"}
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))
print(type(g))
#Output:
<class 'int'>
<class 'str'>
<class 'list'>
<class 'tuple'>
<class 'dict'>
<class 'float'>
<class 'set'>
Hopefully this article has been useful for you to learn how to print the type of a variable in Python.
Leave a Reply