Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python abstract method

# Python program showing
# abstract base class work
 
from abc import ABC, abstractmethod
 
class Polygon(ABC):
 
    @abstractmethod
    def noofsides(self):
        pass
 
class Triangle(Polygon):
 
    # overriding abstract method
    def noofsides(self):
        print("I have 3 sides")
 
class Pentagon(Polygon):
 
    # overriding abstract method
    def noofsides(self):
        print("I have 5 sides")
 
class Hexagon(Polygon):
 
    # overriding abstract method
    def noofsides(self):
        print("I have 6 sides")
 
class Quadrilateral(Polygon):
 
    # overriding abstract method
    def noofsides(self):
        print("I have 4 sides")
 
# Driver code
R = Triangle()
R.noofsides()
 
K = Quadrilateral()
K.noofsides()
 
R = Pentagon()
R.noofsides()
 
K = Hexagon()
K.noofsides()
Comment

abstract class python

An abstract class exists only so that other "concrete" classes can inherit from the abstract class.
Comment

abstract class in python

class Circle(Shape):
    def __init__(self):
        super().__init__("circle")
 
    @property
    def name(self):
        return self.shape_name
 	def draw(self):    
        print("Drawing a Circle")
Comment

Abstract Classes in Python

# Python program showing
# abstract base class work
 
from abc import ABC, abstractmethod
class Animal(ABC):
 
    def move(self):
        pass
 
class Human(Animal):
 
    def move(self):
        print("I can walk and run")
 
class Snake(Animal):
 
    def move(self):
        print("I can crawl")
 
class Dog(Animal):
 
    def move(self):
        print("I can bark")
 
class Lion(Animal):
 
    def move(self):
        print("I can roar")
         
# Driver code
R = Human()
R.move()
 
K = Snake()
K.move()
 
R = Dog()
R.move()
 
K = Lion()
K.move()
Comment

PREVIOUS NEXT
Code Example
Python :: scipy check normal distribution 
Python :: seaborn library in python 
Python :: how to create barcode in python 
Python :: all python functions 
Python :: imagefield django models 
Python :: how to append to a dictionary in python 
Python :: python dictionary comprehensions 
Python :: sympy 
Python :: models in django 
Python :: python track time 
Python :: python np get indices where value 
Python :: download unsplash images python without api 
Python :: python get input 
Python :: cite pandas python 
Python :: python list contains string 
Python :: how to handle missing values in dataset 
Python :: freecodecamp python 
Python :: if statement in python 
Python :: python mqtt subscribe code 
Python :: expand alphabets in python 
Python :: raise_for_status() requests 
Python :: ajouter element liste python 
Python :: Multidimensional Java Array 
Python :: sphinx autodoc command 
Python :: function in the input function python 
Python :: python palindrome check 
Python :: merge keep left index 
Python :: python keyboard 
Python :: method get first last name python 
Python :: flatten list 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =