4

In python class declaration I can declare a class by few ways. What is a difference between following samples?

class MyClass:
 def __init__(self)
     pass


class MyClass(object):
   def __init__(self)
     pass
Arseny
  • 7,251
  • 4
  • 37
  • 52
  • An important question, but one that could have obviously been answered 'self-serve' by reading the docs.. – wim Jan 03 '12 at 11:09

2 Answers2

7

The second declaration creates a new-style class. A new-style class is derived from a built-in type, in this case an object. This was introduced in python 2.2 in an effort to unify classes and types. For backward compatibility old-style classes are still the default

Additional read: http://docs.python.org/release/2.2.3/whatsnew/sect-rellinks.html

Russell Dias
  • 70,980
  • 5
  • 54
  • 71
2

The second way creates a "new-style" class. Documentation is admittedly a bit lacking, as mentioned in a couple places on the python website Python Guide 3.3, and here. There's also an essay describing their design by Python's creator (Guido van Rossum), but it's not strictly documentation.

Alex Leach
  • 1,199
  • 2
  • 12
  • 26