Difference between class foo, class foo () and class foo (object)?

I noticed that all 3 β†’ class foo, class foo()and class foo(object)can be used, but I'm confused as to what is the difference between these 3, if any? (I mean mostly properties python3)

+9
source share
1 answer

Let me break them down:

  • class foo:

    • Python 3: This is usually the way to go. By default, Python adds objectas a base class for you.
    • Python 2: it creates an old style classobjthat will cause you all kinds of headaches.
  • class foo():

    • Python 3 Python 2: class foo Python, , .
  • class foo(object):
    • Python 3 Python 2: Pythons , , . , Python 2, , Python 2 3 ( ).
+13

Source: https://habr.com/ru/post/1015004/


All Articles