DIR ATTRIBUTES PYTHON 2.7 VS PYTHON 3.6
Python 2.7:
Python 3.6:
Differences:
As we can see class A has more available attributes in Python3. Six of them are named “rich comparision”(‘__ne__’, ‘__ge__’, ‘__lt__’, ‘__gt__’, ‘__le__’, ‘__eq__’). To compare object instances you have to override above methods, otherwise TypeError will be raised:
> a <= b
Traceback (most recent call last):
File "python", line 1, in <module>
TypeError: '<=' not supported between instances of 'A' and 'A'
However in Python 2.7 the behaviour is different. It doesn’t raise any error. Of course we can override above methods and it will behave like we want.
__dir__ - return the list of attributes
__init_subclass__ - allows to customize subclass creation without using a metaclass
Congratulations @rafaello! You have received a personal award!
1 Year on Steemit
Click on the badge to view your Board of Honor.
Do not miss the last post from @steemitboard:
SteemitBoard World Cup Contest - Quarter Finals - Day 2
Participate in the SteemitBoard World Cup Contest!
Collect World Cup badges and win free SBD
Support the Gold Sponsors of the contest: @good-karma and @lukestokes
Congratulations @rafaello! You received a personal award!
You can view your badges on your Steem Board and compare to others on the Steem Ranking
Vote for @Steemitboard as a witness to get one more award and increased upvotes!