avatarSamer Sallam

Summary

The provided web content outlines an overview of special methods in Python Object-Oriented Programming (OOP), which are essential for defining behaviors and actions when using operators with class objects, and are covered in Part 11 of a complete OOP course.

Abstract

The article is part of "The Complete Course in Object-Oriented Programming in Python," specifically focusing on special methods in Python OOP as covered in Part 11. It introduces the concept of special methods, also known as dunder methods, which are used to define how custom objects interact with operators like addition. The article aims to equip readers with the understanding and ability to override these methods to suit different programming scenarios. By the end of the section, readers are expected to grasp the purpose of special methods, familiarize themselves with various types, and learn how to customize them for problem-solving. The section includes topics such as initialization, construction, operator overloading, class representation, type conversion, attribute handling, sequence behavior, callable objects, and context managers, concluding with a summary of the learned concepts. The author also encourages readers to subscribe for direct updates and consider Medium membership to support the writer and access more content.

Opinions

  • The author emphasizes the importance of special methods in Python OOP, suggesting that they are crucial for customizing object behavior with operators.
  • The article is presented as both written content and a YouTube video, indicating the author's commitment to diverse learning preferences.
  • The author expresses gratitude for the reader's time and encourages engagement through subscriptions and Medium membership, hinting at the value they place on reader support and community building.
  • By providing a roadmap of the topics covered in the Special Methods section, the author conveys a structured and comprehensive approach to teaching these OOP concepts.
  • The inclusion of real-world scenarios and use cases implies that the course content is practical and application-oriented, aimed at enhancing the reader's programming skills.

Special Methods Overview: Python OOP Complete Course — Part 11

Photo by Josh Sorenson on Pexles

Before we start let me tell you that:

  • This article is a part of The Complete Course in Object Oriented Programming in Python which you can find it here.
  • This article is also available as a YouTube video here.

Introduction

Before I start talking about the special methods and learning objectives of this section, let us try to answer this question: What is the value of “C” in the following expression?

  • A = 1
  • B = 1
  • C = A + B

Simply it is 2 because when we have two variables from the type integer with a plus operator that means we are adding one number to the other.

Now assume you have the following objects from a dummy class:

  • Obj1
  • Obj2
  • C = Obj1 + Obj2

The question now: How do we add one object of a class to another object of the same class? It is weird, right? and if you try to use this syntax in your code, you will get an error because the addition or plus operator is not defined for Python classes by default. So…

Is there a way to define the behavior or the action that should be done when we are using an operator like plus with two objects from a class?

Simply yes there is and we do that by using what we call special methods or dunder methods. Let me tell you that this section will teach you how to use and override these special methods with real scenarios and use cases.

Photo by Hello I’m Nik on Unsplash

By the end of Special Methods section, you will be able to:

  • Understand the meaning of special methods in Python OOP and when you have to use them.
  • Be familiar with most types of special methods in Python.
  • Be able to override these methods and customize their jobs to fit the problem being solved.

In order to achieve all of these objectives, Special Methods section will cover the following topics:

Photo by Dominika Roseclay on Pexles
  1. Introduction to the Special Methods
  2. Initialization and Construction Special Methods
  3. Operators Special Methods
  4. Class Representation Special Methods
  5. Type Conversion Special Methods
  6. Attributes Special Methods
  7. Sequences Special Methods
  8. Callable Objects Special Method
  9. Context Managers Special Methods
  10. Section Conclusion: to summarize what you will learn

Finally, stay tuned and be ready because we have a lot of cool stuff to learn in the Special Methods section.

P.S.: A million thanks for your time reading my story. Before you leave let me mention quickly two points:

  • First, to get my posts in your inbox directly, would you please subscribe here, and you can follow me here.
  • Second, writers made thousands of $$ on Medium. To get unlimited access to Medium stories and start earning, sign up now for Medium membership which only costs $5 per month. By signing up with this link, you can directly support me at no extra cost to you.

To get back to the previous article, you can use the following link:

Part 10:OOP Basics Conclusion

To move on to the next article, you can use the following link:

Part 12:Introduction to Special Methods

Object Oriented
Python
Special Methods
Dunder Method
Magic Method
Recommended from ReadMedium