Python type – find type of a variable

Python in-built function type() can be use to find type of any variable or value.

Example – type() of string variable

v = "Hello"
print type(v)
<type 'str'>
Env: Python 2.7.6

Example – type() of int variable

v = 10
print type(v)
<type 'int'>
Env: Python 2.7.6

Example – type() of None

v =None
print type(v)
<type 'NoneType'>
Env: Python 2.7.6

Example – type() of array/list

v = ["item1", "item2", "item3"]
print type(v)
<type 'list'>
Env: Python 2.7.6

Example – type() of dictionary

v = {"k1":"item1", "k2":"item2"}
print type(v)
<type 'dict'>
Env: Python 2.7.6
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments