Entering[color=blue][color=green][color=darkred]
>>>dir(5)[/color][/color][/color]
I get
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
'__floordiv__', '__getattribute __', '__getnewargs__ ', '__hash__',
'__hex__', '__init__', '__int__', '__invert__', '__long__',
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__',
'__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__',
'__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__' ,
'__repr__', '__rfloordiv__' , '__rlshift__', '__rmod__', '__rmul__',
'__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__',
'__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__',
'__truediv__', '__xor__']
Every time I use dir(some module) I get a lot of attributes with double
underscore, for example __add__. Ok, I thought __add__ must be a method
which I can apply like this[color=blue][color=green][color=darkred]
>>> 5.__add(8)[/color][/color][/color]
However Python responded
SyntaxError: invalid syntax
I tried[color=blue][color=green][color=darkred]
>>> help(5.__add__)[/color][/color][/color]
but got
SyntaxError: invalid syntax
However when I tried with a list[color=blue][color=green][color=darkred]
>>> help([5,6].__add__)[/color][/color][/color]
I got
Help on method-wrapper object:
__add__ = class method-wrapper(object)
| Methods defined here:
|
| __call__(...)
| x.__call__(...) <==> x(...)
|
| __getattribute_ _(...)
| x.__getattribut e__('name') <==> x.name
Not that I understand much of this but at least I got some response.
Now I went to Python Library Reference and searched for "__add__" but
got zero hits.
Could someone explain the use of __add__ (and similar double underscore
attributes) and what their use is.
Bob
>>>dir(5)[/color][/color][/color]
I get
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__',
'__delattr__', '__div__', '__divmod__', '__doc__', '__float__',
'__floordiv__', '__getattribute __', '__getnewargs__ ', '__hash__',
'__hex__', '__init__', '__int__', '__invert__', '__long__',
'__lshift__', '__mod__', '__mul__', '__neg__', '__new__',
'__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__',
'__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__' ,
'__repr__', '__rfloordiv__' , '__rlshift__', '__rmod__', '__rmul__',
'__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__',
'__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__',
'__truediv__', '__xor__']
Every time I use dir(some module) I get a lot of attributes with double
underscore, for example __add__. Ok, I thought __add__ must be a method
which I can apply like this[color=blue][color=green][color=darkred]
>>> 5.__add(8)[/color][/color][/color]
However Python responded
SyntaxError: invalid syntax
I tried[color=blue][color=green][color=darkred]
>>> help(5.__add__)[/color][/color][/color]
but got
SyntaxError: invalid syntax
However when I tried with a list[color=blue][color=green][color=darkred]
>>> help([5,6].__add__)[/color][/color][/color]
I got
Help on method-wrapper object:
__add__ = class method-wrapper(object)
| Methods defined here:
|
| __call__(...)
| x.__call__(...) <==> x(...)
|
| __getattribute_ _(...)
| x.__getattribut e__('name') <==> x.name
Not that I understand much of this but at least I got some response.
Now I went to Python Library Reference and searched for "__add__" but
got zero hits.
Could someone explain the use of __add__ (and similar double underscore
attributes) and what their use is.
Bob
Comment