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 :: convert excel file to csv with pandas 
Python :: how to write to a netcdf file using xarray 
Python :: python use variable in regex expression 
Python :: tkmessagebox not found 
Python :: or condition in pandas 
Python :: loop append to list python 
Python :: api in python 
Python :: python get value from decimal object 
Python :: TypeError: cannot unpack non-iterable int object 
Python :: what is kali 
Python :: list comprehenstsion using lambda funcion 
Python :: playsound error python 
Python :: python manage.py collectstatic --noinput 
Python :: create dictionary from input python 
Python :: how to make calculator in python 
Python :: how to reboot a python script 
Python :: true positive true negative manually 
Python :: No package python37 available. 
Python :: python list comprehension elif 
Python :: clean punctuation from string python 
Python :: how to remove rows with certain values pandas 
Python :: python compute SSIM 
Python :: pandas select columns by index 
Python :: image rotate in python 
Python :: instabot python 
Python :: affinity propagation python 
Python :: import local module python 
Python :: unshorten url python 
Python :: make entry bigger in tkinter python 
Python :: python cheat sheet 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =