Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

extend a class python

# there is no extend keyword used in Python
# line #7 below is equivalent to "class Circle extends Shape" (in JAVA)

class Shape(object):
   pass

class Circle(Shape):   # in python we use superclass as arg to EXTEND Shape
   pass 

s = Shape()
c = Circle()
print(isinstance(s, Shape))
print(isinstance(c, Circle))
print(isinstance(c, Shape))
print(isinstance(s, Circle))
#  
# output
# True (s is an instance of Shape )
# True (c is an instance of Circle )
# True (c is also an instance of Shape )
# False (s is NOT an instance of Circle because Shape is a subclass )
 
PREVIOUS NEXT
Tagged: #extend #class #python
ADD COMMENT
Topic
Name
5+3 =