DIR ATTRIBUTES PYTHON 2.7 VS PYTHON 3.6

in #programming6 years ago

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 

Sort:  

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


Do you like SteemitBoard's project? Then Vote for its witness and get one more award!

Congratulations @rafaello! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

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!

Coin Marketplace

STEEM 0.16
TRX 0.13
JST 0.027
BTC 58188.83
ETH 2585.51
USDT 1.00
SBD 2.40