Question:

Which methods of Python are used to determine the type of instance and inheritance?

Answer:

Python has 2 built-in functions that work with inheritance:
isinstance() – this method checks the type of instance.
o for eg, isinstance(myObj, int) – returns True only when “myObj. class ” is “int”.
issubclass() – this method checks class inheritance
o for eg: issubclass(bool, int) – returns True because “bool” is a subclass of “int”.
o issubclass(unicode, str) – returns False because “unicode” is not a subclass of “str”.


Keywords:

© 2017 QuizBucket.org