user4084
-1
Q:

type in 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'>
1
## To get the type of a variable, use 'type()'
type("Hello World!")
## Output:
## str
2
isinstance(object, classinfo) 
The isinstance() takes two parameters:
object : object to be checked
classinfo : class, type, or tuple of classes and types
1
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'>
0

New to Communities?

Join the community