“Metode abstrak Python” Kode Jawaban

Metode abstrak Python

# 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

Kelas Abstrak dalam 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

Contoh Kelas Abstrak Python

Abstract Class
Lazy Llama

Jawaban yang mirip dengan “Metode abstrak Python”

Pertanyaan yang mirip dengan “Metode abstrak Python”

Lebih banyak jawaban terkait untuk “Metode abstrak Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya