Google News
logo
Python Program to Verify the type of an Object
In the following example of Python program that demonstrates how to verify the type of an object :
Program :
# Creating variables of different types
num = 10
text = "Hello, world!"
lst = [1, 2, 3]

# Checking the types of the variables
print(type(num))   # int
print(type(text))  # str
print(type(lst))   # list
Output :
<class 'int'>
<class 'str'>
<class 'list'>
In this program, we create three variables of different types: an integer (`num`), a string (`text`), and a list (`lst`). We then use the `type` function to verify the type of each variable and output the results using the `print` function.

The `type` function returns the data type of the object that it is passed as an argument. In this program, we pass the variables `num`, `text`, and `lst` to the `type` function, which returns the types `int`, `str`, and `list`, respectively.

You can use the `type` function to verify the types of any objects in your Python program, including variables, functions, and modules. This can be useful when debugging your code or when working with libraries or external code that you're not familiar with.