Python issubclass()

Configurare noua (How To)

Situatie

The issubclass() function checks if the class argument (first argument) is a subclass of classinfo class (second argument).

issubclass() returns:

  • True if class is subclass of a class, or any element of the tuple
  • False otherwise

Solutie

Pasi de urmat

class Polygon:
def __init__(polygonType):
print(‘Polygon is a ‘, polygonType)

class Triangle(Polygon):
def __init__(self):

Polygon.__init__(‘triangle’)

print(issubclass(Triangle, Polygon))
print(issubclass(Triangle, list))
print(issubclass(Triangle, (list, Polygon)))
print(issubclass(Polygon, (list, Polygon)))

Output:

True
False
True
True

Tip solutie

Permanent

Voteaza

(0 din 3 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?