101.school
CoursesAbout
Search...⌘K
Generate a course with AI...

    Python

    Receive aemail containing the next unit.
    • Refreshing Python Basics
      • 1.1Python Data Structures
      • 1.2Syntax and Semantics
      • 1.3Conditionals and Loops
    • Introduction to Object-Oriented Programming
      • 2.1Understanding Class and Objects
      • 2.2Design Patterns
      • 2.3Inheritance, Encapsulation, and Polymorphism
    • Python Libraries
      • 3.1Numpy and Matplotlib
      • 3.2Pandas and Seaborn
      • 3.3SciPy
    • Handling Files and Exception
      • 4.1Reading, writing and manipulating files
      • 4.2Introduction to Exceptions
      • 4.3Handling and raising Exceptions
    • Regular Expressions
      • 5.1Introduction to Regular Expressions
      • 5.2Python’s re module
      • 5.3Pattern Matching, Substitution, and Parsing
    • Databases and SQL
      • 6.1Introduction to Databases
      • 6.2Python and SQLite
      • 6.3Presentation of Data
    • Web Scraping with Python
      • 7.1Basics of HTML
      • 7.2Introduction to Beautiful Soup
      • 7.3Web Scraping Case Study
    • Python for Data Analysis
      • 8.1Data cleaning, Transformation, and Analysis using Pandas
      • 8.2Data visualization using Matplotlib and Seaborn
      • 8.3Real-world Data Analysis scenarios
    • Python for Machine Learning
      • 9.1Introduction to Machine Learning with Python
      • 9.2Scikit-learn basics
      • 9.3Supervised and Unsupervised Learning
    • Python for Deep Learning
      • 10.1Introduction to Neural Networks and TensorFlow
      • 10.2Deep Learning with Python
      • 10.3Real-world Deep Learning Applications
    • Advanced Python Concepts
      • 11.1Generators and Iterators
      • 11.2Decorators and Closures
      • 11.3Multithreading and Multiprocessing
    • Advanced Python Concepts
      • 12.1Generators and Iterators
      • 12.2Decorators and Closures
      • 12.3Multithreading and Multiprocessing
    • Python Project
      • 13.1Project Kick-off
      • 13.2Mentor Session
      • 13.3Project Presentation

    Introduction to Object-Oriented Programming

    Understanding Inheritance, Encapsulation, and Polymorphism in Python

    In this unit, we will delve into three fundamental concepts of Object-Oriented Programming (OOP) - Inheritance, Encapsulation, and Polymorphism - and how they are implemented in Python.

    Inheritance

    Inheritance is a way of creating a new class using details of an existing class without modifying it. The newly formed class is a derived class (or child class). The existing class is a base class (or parent class).

    Python supports several types of inheritance:

    • Single Inheritance: When a child class inherits from a single parent class.
    • Multiple Inheritance: When a child class inherits from more than one parent class.
    • Multilevel Inheritance: When a child class becomes a parent class for another child class.
    • Hierarchical Inheritance: When one class serves as a superclass (base class) for more than one subclass.
    • Hybrid Inheritance: A combination of multiple and multilevel inheritance.

    Encapsulation

    Encapsulation is one of the fundamental concepts in OOP. It describes the idea of wrapping data and the methods that work on data within one unit. This puts restrictions on accessing variables and methods directly and can prevent the accidental modification of data.

    In Python, we denote private attributes using underscore as the prefix i.e single _ or double __.

    Polymorphism

    Polymorphism is an ability (in OOP) to use a common interface for multiple forms (data types).

    Suppose, we need to color a shape, there are multiple shape options (rectangle, square, circle). However we could use the same method to color any shape. This concept is called Polymorphism.

    In Python, Polymorphism allows us to define methods in the child class with the same name as defined in their parent class.

    Operator Overloading

    Python operators work for built-in classes. But the same operator behaves differently with different types. This feature in Python, that allows the same operator to have different meaning according to the context is called operator overloading.

    Method Overloading and Overriding

    In Python, we can define a method in such a way that there are multiple ways to call it. This is known as method overloading.

    Method overriding is an ability of any object-oriented programming language that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its super-classes or parent classes.

    By understanding these concepts, you will be able to write more efficient and effective Python code, leveraging the full power of Object-Oriented Programming.

    Test me
    Practical exercise
    Further reading

    Good morning my good sir, any questions for me?

    Sign in to chat
    Next up: Numpy and Matplotlib