“Python abstrakte Methode” Code-Antworten

Python abstrakte Methode

# 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()
Prickly Partridge

Zusammenfassung Klasse 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")
Charming Caterpillar

Beispiel für abstrakte Klasse Python

Abstract Class
Lazy Llama

Ähnliche Antworten wie “Python abstrakte Methode”

Fragen ähnlich wie “Python abstrakte Methode”

Weitere verwandte Antworten zu “Python abstrakte Methode” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen