type() function in python

In python programming, there is no need to specify the type of the object when you declare a variable. If you want to get the type of a variable then the type() function is used.
type() function is used to find the type of any variable or object.

Syntax of type() function in python
syntax : type(object)
HOW TO FIND THE TYPE OF VARIABLE IN PYTHON

type function in python

Python type() Function Examples
print(type(100)) 

#Output: <class 'int'>
HOW TO FIND THE TYPE OF VARIABLE IN PYTHON

type function python

Python type() Function Examples
a = "Hello" 
print(type(a))

#Output:  <class 'str'>
'''If we want to check type of the variable then we will use type().'''

a = 10
print(a,type(a)) 
# output: 10 <class 'int'>

b = 10.9
print(b,type(b)) #Output: 10.9 <class 'float'>

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

d = [12,32,45,34]
print(d,type(d))
#Output: [12, 32, 45, 34] <class 'list'>

Check Your Knowledge

Python type() Function Quiz

Read More Educational Posts