type of python code example
Example 1: type of object python
>>> type([]) is list
True
>>> type({}) is dict
True
>>> type('') is str
True
>>> type(0) is int
True
Example 2: check type of variable in python
str = "Hello"
type(str)
Example 3: type python
string_example = "string"
int_example = 1
float_example = 1.1
type_of_string = type(string_example)
type_of_int = type(int_example)
type_of_float = type(float_example)
Example 4: python typeof
type(object)
Example 5: type in python
numbers_list = [1, 2]
print(type(numbers_list))
numbers_dict = {1: 'one', 2: 'two'}
print(type(numbers_dict))
class Foo:
a = 0
foo = Foo()
print(type(foo))
Output
<class 'dict'>
<class 'Foo'>
<class '__main__.Foo'>