Get type of object in Python 3.10

Find this useful? Support us: Star on GitHub 6
Category: Type | Language: Python 3.10

In Python 3.10, you can get the type of an object by using the built-in type() function. Here's an example:

# Example 1
x = 5  # integer
print(type(x))  # 

# Example 2
y = 4.5 # float
print(type(y)) #

# Example 3
z = "hello" # string
print(type(z)) #

# Example 4
w = [1, 2, 3] # list
print(type(w)) #

In these examples, we define variables x, y, z, and w of different types, and use type() to obtain their types. Note that the output of type() includes the class keyword, followed by the name of the class (e.g. int, float, str, list, etc.).