Skip to content

Latest commit

 

History

History
38 lines (29 loc) · 2.23 KB

Python_04_OOP.md

File metadata and controls

38 lines (29 loc) · 2.23 KB

🐍 Object Oriented Programming 🤖

Table of Contents

  1. Classes & Objects
  2. Defining a Class
  3. Creating Objects
  4. Object Functions
  5. Inheritance
  6. Practical Examples

Classes & Objects

  • Overview: Discusses the importance of classes and objects in Python for organizing and enhancing programs.
  • Real-World Modeling: Explains how classes and objects allow for modeling real-world entities that can't be represented by basic data types like strings or numbers.
  • Creating Custom Data Types: Demonstrates how to create custom data types using classes, using the example of a Student class.

Defining a Class

  • Creating a Class: Shows how to define a class in Python, using class ClassName:.
  • Initialization Function: Explains the use of the __init__ function for initializing class attributes.
  • Attributes: Discusses defining attributes like name, major, GPA, and is_on_probation within a class.

Creating Objects

  • Instantiating Objects: Covers creating instances of a class, known as objects.
  • Assigning Values to Objects: Details how to assign values to object attributes during instantiation.

Object Functions

  • Defining Functions in Classes: Illustrates how to define functions within a class that can operate on object attributes.
  • Example Function: Provides an example function on_honor_roll to determine if a student's GPA qualifies for the honor roll.

Inheritance

  • Concept of Inheritance: Introduces the concept of inheritance in Python, where a class can inherit attributes and methods from another class.
  • Creating Inherited Classes: Shows how to create a class that inherits from another, using the example of a ChineseChef class inheriting from a Chef class.
  • Overriding Methods: Discusses how inherited classes can override methods from the parent class.

Practical Examples

  • Chef Class Example: Uses the example of a Chef class with methods like make_chicken and make_special_dish.
  • Chinese Chef Extension: Explores extending the Chef class to a ChineseChef class, demonstrating inheritance and method overriding.