Abstraction in
Python
What is abstraction
 Abstraction is used to hide the internal functionality of the function from the
users. The users only interact with the basic implementation of the function,
but inner working is hidden. User is familiar with that "what function
does" but they don't know "how it does."
Why Abstraction is Important?
 In Python, an abstraction is used to hide the irrelevant data/class in order to
reduce the complexity. It also enhances the application efficiency.
 Abstraction is essential to hide the core functionality from the users.
Why use Abstract Base Classes :
 By defining an abstract base class, we can define a common Application
Program Interface(API) for a set of subclasses. This capability is especially
useful in situations where a third-party is going to provide implementations,
such as with plugins
 Let us understand with example
 From abc import ABC, abstractmethod
 Class animal(ABC): -----this is abstract base class(must have at least one abstract method)
 @abstractmethod -----this decorator is used to create a abstract method
 def move(self):
 pass Note*: We can’t instantiate or create object of abstract class
Class human(animal): ---- this class is inherited from base/parent class
def move(self): --- overriding the abstract method
print(“I Can Walk and Run”)
Class lion(animal):
Def move(self):
print(“I Can Roar”)
h=human()
h.move()
References:
https://www.geeksforgeeks.org/abstract-classes-in-python/
https://www.javatpoint.com/abstraction-in-python
Thank you..!

Abstraction in Python - Presentation.pptx

  • 1.
  • 2.
    What is abstraction Abstraction is used to hide the internal functionality of the function from the users. The users only interact with the basic implementation of the function, but inner working is hidden. User is familiar with that "what function does" but they don't know "how it does."
  • 3.
    Why Abstraction isImportant?  In Python, an abstraction is used to hide the irrelevant data/class in order to reduce the complexity. It also enhances the application efficiency.  Abstraction is essential to hide the core functionality from the users.
  • 4.
    Why use AbstractBase Classes :  By defining an abstract base class, we can define a common Application Program Interface(API) for a set of subclasses. This capability is especially useful in situations where a third-party is going to provide implementations, such as with plugins  Let us understand with example
  • 5.
     From abcimport ABC, abstractmethod  Class animal(ABC): -----this is abstract base class(must have at least one abstract method)  @abstractmethod -----this decorator is used to create a abstract method  def move(self):  pass Note*: We can’t instantiate or create object of abstract class Class human(animal): ---- this class is inherited from base/parent class def move(self): --- overriding the abstract method print(“I Can Walk and Run”) Class lion(animal): Def move(self): print(“I Can Roar”) h=human() h.move()
  • 6.
  • 7.