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 :: dictionaries in python 
Python :: how to iterate tuple in python 
Python :: how to watermark a video using python 
Python :: rotatelist in python 
Python :: discord.py 
Python :: Try using .loc[row_indexer,col_indexer] = value instead 
Python :: how to make a calcukatir in python 
Python :: python string operations 
Python :: Convert .tif images files to .jpeg in python 
Python :: infinite for loop in python 
Python :: api key python 
Python :: use chrome console in selenium 
Python :: python sort dictionary case insensitive 
Python :: time series python 
Python :: Python Tkinter ListBox Widget Syntax 
Python :: receipt ocr 
Python :: is microsoft teams free 
Python :: python list to sublists 
Python :: arch python 
Python :: Math Module radians() Function in python 
Python :: how to print multiple integers in python in different line 
Python :: simple click counter in python 
Python :: img_sm = pygame.transform.scale(img, (32, 32)) 
Python :: proxy pool for scrapy 
Python :: emacs pipenv not working 
Python :: roll dice python 
Shell :: git ignore permission changes 
Shell :: stop apache server 
Shell :: ubuntu media codecs 
Shell :: install framer motion 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =