
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Determine if a class is a subclass of a second class in Python
To determine if a class is a subclass of a second class, use the numpy.issubclass_() method in Python numpy. The 1st argument is the input class. True is returned if arg1 is a subclass of arg2. The 2nd argument is the input class. If a tuple of classes, True is returned if arg1 is a subclass of any of the tuple elements. The issubclass_ is equivalent to the Python built-in issubclass, except that it returns False instead of raising a TypeError if one of the arguments is not a class.
Steps
At first, import the required library −
import numpy as np
Using the issubclass_() method in Numpy. Checking whether a class is a subclass of a second class −
print("Result...",np.issubclass_(np.float16, np.float32)) print("Result...",np.issubclass_(np.int32, np.signedinteger)) print("Result...",np.issubclass_('i4', np.signedinteger)) print("Result...",np.issubclass_(np.int64, int)) print("Result...",np.issubclass_(np.float64, float)) print("Result...",np.issubclass_('S8', str)) print("Result...",np.issubclass_(np.int16, float)) print("Result...",np.issubclass_(np.array([45, 89]), int)) print("Result...",np.issubclass_(np.int32, np.integer))
Example
import numpy as np # To determine if a class is a subclass of a second class, use the numpy.issubclass_() method in Python numpy # The 1st argument is the input class. True is returned if arg1 is a subclass of arg2. # The 2nd argument is the input class. If a tuple of classes, True is returned if arg1 is a subclass of any of the tuple elements. # The issubclass_ is equivalent to the Python built-in issubclass, # except that it returns False instead of raising a TypeError if one of the arguments is not a class. print("Using the issubclass_() method in Numpy\n") # Checking whether a class is a subclass of a second class print("Result...",np.issubclass_(np.float16, np.float32)) print("Result...",np.issubclass_(np.int32, np.signedinteger)) print("Result...",np.issubclass_('i4', np.signedinteger)) print("Result...",np.issubclass_(np.int64, int)) print("Result...",np.issubclass_(np.float64, float)) print("Result...",np.issubclass_('S8', str)) print("Result...",np.issubclass_(np.int16, float)) print("Result...",np.issubclass_(np.array([45, 89]), int)) print("Result...",np.issubclass_(np.int32, np.integer))
Output
Using the issubclass_() method in Numpy Result... False Result... True Result... False Result... False Result... True Result... False Result... False Result... False Result... True
- Related Articles
- How do we check if a class is a subclass of the given super class in Python?
- Determine if the type in the first argument is a subclass of second in Python
- How do I make a subclass from a super class in Python?
- Using a Frame class in a Tk class in Python tkinter
- Variable in subclass hides the variable in the super class in Java
- How to define attributes of a class in Python?
- How to serialize a Python class?
- What is a class in JavaScript?
- What are static methods in a Python class?
- Can private methods of a class be accessed from outside of a class in Java?
- How to dynamically load a Python class?
- How do I enumerate functions of a Python class?
- How to check if an object is an instance of a Class in JavaScript?
- The class size of a distribution is 25 and the first class-interval is $200-224$. There are seven class-intervals.Write the class-intervals.
- What is a static class in Java?

Advertisements