Python operator Overloading

Source: Internet
Author: User

Constructors and Expressions: __init__, __sub__ common operator overloading methods
Method Reload Pager
__init__ constructor function Object creation: X = Class (args)
__del__ Destructors X Object retract
__add__ Cloud Algorithm + If there is no _iadd_, X+y, x+=y
__or__ operator | If there is no _ior_,x| Y, X|=y
_REPR__, __str__ Print, convert Print (x), repr (x), str (x)
__call__ Function call X (*args, **kwargs)
__getattr__ Point number arithmetic x.undefined
__setattr__ Property Assignment Statements X.any=value
__delattr__ Property Delete Del X.any
__getattribute__ Property gets X.any
__getitem__ Index operations X[KEY],X[I:J]
__setitem__ Index assignment statement X[key],x[i:j]=sequence
__delitem__ Index and Shard deletion Del X[key],del X[i:j]
__len__ Length Len (X), if there is no __bool__, the truth test
__bool__ Boolean test BOOL (X)
__lt__, __gt__,
__le__, __ge__,
__eq__, __ne__
A specific comparison X<y,x>y,x<=y,x>=y,
X==y,x!=y
Note: (lt:less than, gt:greater than,
le:less equal, Ge:greater equal,
Eq:equal, Ne:not Equal
__radd__ Right addition Other+x
__iadd__ field (Enhanced) addition X+=y (or else __add__)
__ITER__, __next__ Iterative environment I=iter (X), Next ()
__contains__ Member Relationship Testing Item in X (any iteration possible)
__index__ Integer value Hex (x), Bin (x), Oct (x)
__ENTER__, __exit__ Environment Manager With obj as Var:
__get__, __set__,
__delete__
Descriptor Properties X.attr, X.attr=value, Del x.attr
__new__ Create Create an object before __init__

Python operator Overloading

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.