In my research I found that in Python 3 these three types of class definition are synonymous:
class MyClass:
pass
class MyClass():
pass
class MyClass(object):
pass
However, I was not able to find out which way is recommended. Which one should I use as a best practice?
I would say: Use the third option:
class MyClass(object):
pass
It explicitly mentions that you want to subclass object
(and doesn't the Zen of Python mention: "Explicit is better than implicit.") and you don't run into nasty errors in case you (or someone else) ever run the code in Python 2 where these statements are different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With