type object python code example

Example 1: print variable type python

v = 10
type(v)
# <type 'int'>

Example 2: type of object python

>>> type([]) is list
True
>>> type({}) is dict
True
>>> type('') is str
True
>>> type(0) is int
True

Example 3: python get type of variable

>>> i = 123
>>> type(i)
<type 'int'>
>>> type(i) is int
True
>>> i = 123.456
>>> type(i)
<type 'float'>
>>> type(i) is float
True

Example 4: type python

#This is able to tell the user what the type of an object is
string_example = "string"
int_example = 1
float_example = 1.1
type_of_string = type(string_example)
#<class 'str'>
type_of_int = type(int_example)
#<class 'int'>
type_of_float = type(float_example)
#<class 'float'>

Tags:

Java Example