How to Check the Type of an Object in Python?

Estimated read time 1 min read

In Python, you can check the type of an object using the type() function. Here is an example:

x = 5
print(type(x)) # Output: <class 'int'>

In the above example, the type() function is used to check the type of the x object, which is an integer. The output shows that the type of x is <class 'int'>.

Here is another example using a string:

y = "Hello, world!"
print(type(y)) # Output: <class 'str'>

In this example, the type() function is used to check the type of the y object, which is a string. The output shows that the type of y is <class 'str'>.

You can use the type() function to check the type of any object in Python, including integers, strings, lists, tuples, dictionaries, and more.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply