Answers for "what is abstract class in python"

12

what is abstract class in python

when we use abstract classes? supposably we have class Car. 
you don't want to use it directly. you need extend this class. 
thats why you must declare this class as abstract. 
then you only can extend this class with all methods.
Posted by: Guest on October-16-2021
4

python abstract class

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

Output:

I can walk and run
I can crawl
I can bark
I can roar
Posted by: Guest on May-14-2020
0

abstarct class python

import abc
class Shape(metaclass=abc.ABCMeta):
   @abc.abstractmethod
   def area(self):
      pass
class Rectangle(Shape):
   def __init__(self, x,y):
      self.l = x
      self.b=y
   def area(self):
      return self.l*self.b
r = Rectangle(10,20)
print ('area: ',r.area())
Posted by: Guest on December-05-2020
4

abstract class python

An abstract class exists only so that other "concrete" classes can inherit from the abstract class.
Posted by: Guest on July-17-2021
0

abstarct class python

from abc import ABC

class MyABC(ABC):
    pass
Posted by: Guest on December-05-2020

Code answers related to "what is abstract class in python"

Browse Popular Code Answers by Language