Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference in Python class declaration [duplicate]

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
like image 373
Arseny Avatar asked Oct 19 '25 21:10

Arseny


1 Answers

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

like image 163
Russell Dias Avatar answered Oct 22 '25 11:10

Russell Dias



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!