Python Forum
some dict's special methods
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
some dict's special methods
#6
(Dec-18-2018, 05:02 PM)nzcan Wrote: does it means that behind every dict's built-in method stay one dict's special method?
No, I don't know how you come to that conclusion. As it state in the docs
Quote:A class can implement certain operations that are invoked by special syntax (such as arithmetic operations or subscripting and slicing) by defining methods with special names. This is Python’s approach to operator overloading, allowing classes to define their own behavior with respect to language operators.
That's true for every class, builtin or custom.
>>> dir(dict)
['__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
e.g. __str__ is called when you do str(some_dict)
special methods are methods/attributes, there is no other front-line methods/attribute
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
some dict's special methods - by nzcan - Dec-18-2018, 03:20 PM
RE: some dict's special methods - by buran - Dec-18-2018, 03:24 PM
RE: some dict's special methods - by nzcan - Dec-18-2018, 04:16 PM
RE: some dict's special methods - by buran - Dec-18-2018, 04:33 PM
RE: some dict's special methods - by nzcan - Dec-18-2018, 05:02 PM
RE: some dict's special methods - by buran - Dec-18-2018, 07:29 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020