From the course: Advanced Python

Unlock the full course today

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

Object operations

Object operations - Python Tutorial

From the course: Advanced Python

Start my 1-month free trial

Object operations

- [Narrator] Using special class methods, you can give your classes abilities that they don't natively get from Python, but that other build-in objects have. One of those is the ability to emulate the behavior of numeric values in order to support operations like addition and subtraction. This table shows a partial list of the functions your class can override in order to provide number-like functionality. You can add objects together, subtract them from each other, basically, just about any mathematical operation you want. You can see in the right hand column the kinds of expressions that cause these functions to be called, such as when two objects are added together. In addition, Python also supports in-place math operations on objects. These functions are called when you use the short-hand notation such as plus equals in order to add to an existing object in place. And again, this is not an exhaustive list. If you want to learn more about these functions, you can check out the data…

Contents