How to view the variable type in python?

In Python, you can use the type() function to check the type of a variable. For example:

x = 5
y = "Hello"
z = [1, 2, 3]

print(type(x))  # <class 'int'>
print(type(y))  # <class 'str'>
print(type(z))  # <class 'list'>

The ‘type()’ function here will return the type of a variable, which is an object of type. You can use the ‘str()’ function to convert the type object into a string form for easier readability of the variable’s type.

bannerAds