

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Polymorphism
incomplete
2: Get Edges
incomplete
3: Overlap
incomplete
4: Dragon Area
incomplete
5: Polymorphism Review
incomplete
6: Operator Overloading
incomplete
7: Operator Overload Review
incomplete
8: Overriding Built-in Methods
incomplete
9: Polymorphism Practice
incomplete
10: Polymorphism Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
As we discussed in the last assignment, operator overloading is the practice of defining custom behavior for standard Python operators. Here's a list of how the operators translate into method names.
| Operation | Operator | Method |
|---|---|---|
| Addition | + | __add__ |
| Subtraction | - | __sub__ |
| Multiplication | * | __mul__ |
| Power | ** | __pow__ |
| Division | / | __truediv__ |
| Floor Division | // | __floordiv__ |
| Remainder (modulo) | % | __mod__ |
| Bitwise Left Shift | << | __lshift__ |
| Bitwise Right Shift | >> | __rshift__ |
| Bitwise AND | & | __and__ |
| Bitwise OR | | | __or__ |
| Bitwise XOR | ^ | __xor__ |
| Bitwise NOT | ~ | __invert__ |