Wednesday, March 18, 2015

type() - Python Tutorial


The type() built-in Python function gives us the ability to check the type information of an object via the variable.


Type() Built-In Python Function Example


#Create a variable
>>> a = 9
#Call the variable
>>> a
9
#Check the type of the object
>>> type(a)
<class 'int'>
#create a variable containing a string
>>> b = "string"
#check the type of the object
>>> type(b)
<class 'str'>
#Create a variable
>>> c = "apple": 5, "banana": 3
#check the type
>>> type(c)
<class 'dict'>

 



No comments:

Post a Comment