Operator related magic methods
There are too many magic methods related to operators. J will roughly list the following two categories:
1. Comparison operators
Magic method | Description |
if This method returns a negative number, indicating self < other; Returns a positive number, indicating self > other; Returns 0, indicating self == other. It is strongly not recommended to define __cmp__. Instead, it is best to define __lt__, __eq__ and other methods separately to implement the comparison function. __cmp__ is deprecated in Python3. | |
Defines the behavior of the comparison operator == | |
Defines the behavior of comparison operator != | |
Defines the behavior of comparison operator < | |
Defines the behavior of the comparison operator> | |
Defines the behavior of the comparison operator <= | |
Defines the behavior of the comparison operator >= |
Magic Method | Instructions |
__add__(self, other) | Implements the addition operation |
__sub__(self, other) | Implements the subtraction operation |
__mul__(self, other) | Implements the multiplication operation |
__floordiv__( self, other) | Implements the // operator |
___div__(self, other) | Implements the / operator. This method is available in Python3 Deprecated. The reason is that in Python3, division defaults to true division |
__truediv__(self, other) | implements true division. Only if you declare from __future__ import division This method will take effect |
__mod__(self, other) | Implements the % operator and remainder operation |
__divmod__(self, other) | Implements the divmod() built-in function |
__pow__(self, other) | Implements the ** operation. Nth power operation |
__lshift__(self, other) | implements bit operation<< |
__rshift__( self, other) | Implements bit operations>> |
Implements bit operations& | |
Implements bit operations` | |
Implemented bit operations^ |
- Course Recommendations
- Courseware download
-
ElementaryPython programming introductory series of graphic tutorials
35514 people are watching -
ElementaryScala Tutorial
13058 people are watching -
ElementaryCSS Online Manual
81539 people are watching -
ElementarySVG Tutorial
12628 people are watching -
ElementaryAngularJS Chinese Reference Manual
24072 people are watching -
ElementaryGo language tutorial manual
26840 people are watching -
ElementaryRedis command operation Chinese manual
57363 people are watching -
ElementaryPython 3 Tutorial
87070 people are watching -
ElementaryXML DOM tutorial
20611 people are watching -
ElementaryMemcached command operation manual
17401 people are watching -
ElementaryXSLT tutorial
9479 people are watching -
ElementaryXQuery Tutorial
8791 people are watching
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)