Issubclass () function in Python
The issubclass () function is built into Python to check if an object is a subclass of classinfo.
The built-in issubclass () function checks whether an object (first parameter) is a subclass of classinfo (the second parameter).
The issubclass () function syntax in Python
issubclass(object, classinfo)
Parameters of issubclass function ()
Issubclass () has 2 parameters:
object: object to checkclassinfo: class, type, or tuple
Value returned from issubclass ()
Function issubclass () returns:
Trueif the object is a subclass subclass of the class or any element of the tuple.Falseif vice versa.
Example: How is issubclass () function?
class DaGiac: def __init__(loaiDagiac): print('Da giac la ', loaiDagiac) class TamGiac(DaGiac): def __init__(self): DaGiac.__init__('tamgiac') print(issubclass(TamGiac, DaGiac)) print(issubclass(TamGiac, list)) print(issubclass(TamGiac, (list, DaGiac))) print(issubclass(DaGiac, (list, DaGiac)))
Run the program, the result is:
True False True True
Note that the class is also considered a subclass of itself.
See also: Built-in Python functions
You've just finished reading the article "Issubclass () function in Python" edited by the TipsMake team. You can save issubclass-function-in-python.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.
- Zip () function in Python
- Int () function in Python
- The function id () in Python
- The oct () function in Python
- The next () function in Python
- Hex () function in Python
- The map () function in Python
- The function dir () in Python
- The function set () in Python
- Help () function in Python
- Sum () function in Python
- The slice () function in Python
- The chr () function in Python
- The pow () function in Python