I've been reading up on python's special class methods in Dive into Python, and it seems like some methods have odd or inconsistent syntax.
To get the items from a dictionary you would call the dictionary class method items()
>>> my_dictionary.items()
[('name', 'Old Gregg'), ('Race', 'Scaly Man-Fish')]
However, to determine the number of keys in that dictionary you would call len() and supply it with the dictionary as an argument.
>>> len(my_dictionary)
2
I always assumed that methods like len() weren't actually part of whatever class you called them on given their syntax but after reading chapter 5 of Dive into Python I see that len() actually does result in a dictionary method being called.
my_dictionary.__len__()
So why isn't it and methods like it called like a typical class method?
my_dictionary.len()
Is there a convention I'm unaware of?