From the course: Transition from C# to Python

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Magic methods and properties

Magic methods and properties

From the course: Transition from C# to Python

Start my 1-month free trial

Magic methods and properties

- [Tutor] All right, let's wrap up this chapter by learning about some of Python's so-called magic methods. And these are methods that are common to all Python objects because they are implemented on the base object class in Python. And C# kind of has something similar. If you take a look at the base class object in C#, and if I scroll down to the methods, you'll see that there are about eight or so methods that all objects have such as ToString and Equals and GetHashCode and then there's some others. Your subclasses can override these methods to provide some common functionality in C#, like comparing itself to another object or an object giving a string representation of itself. So, Python really takes this idea and just runs with it. So if you look at the docs for the Python data model and then you click over here on special method names and you start scrolling down, you'll see that there are a lot of these, and some of…

Contents