Skip to main content

What is type()?

The type() function in Python returns the type of an object. It can be used to determine the data type of elements in a list.

# Basic use of type()
x = 10
print(type(x)) # Output: <class 'int'>

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

z = 3.5
print(type(y)) # Output: <class 'float'>

k = True
print(type(k)) # <class 'bool'>

Lets practice type()

###Please mention the type of the following variables and operations in the comment below The options are: str, int, float, bool

x=10.0
print(type(x))

x = x + 5
print(type(x))

x=10 + int(x)
print(type(x))

x = x + float(5)
print(type(x))

s = 1
t = s * 10
print(type(t))

s = "1"
t = s * 10
print(type(t))

s = "1"
t = float(s) * 10
print(type(t))

n1 = 10
n2 = 10
n3 = n1 = n2
print(type(n3))

n1 = 10
n2 = 10
n3 = n1 == n2
print(type(n3))

n1 = 10
n2 = 10
n3 = n1 == n2
n4 = n3 + 5
print(type(n4))


n1 = 10
n2 = 20
n3 = n1 == n2
n4 = n3 + 5
print(n4)
print(type(n4))

n1 = 10
n2 = 10
n3 = n1 == n2
n3 = n3 + int("1")
print(type((n3)))