Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Python, what is the difference between "class name(object):" and "class name():"

Tags:

python

object

What is the difference between the two classes below? Do you have some related information about this case? Thank you very much.

class test(object):
  def __init__(self, name):
     print name

class test():
  def __init__(self, name):
     print name
like image 992
xiaoke Avatar asked Sep 14 '12 15:09

xiaoke


1 Answers

In python 2.x, the class that inherits from object will be a new-style class, while the other won't, while in python 3.x there'll be both new-style.

However, the differences between new and old are rather advanced, (for example, attribute search order) so a beginner shouldn't be too concerned about the incompatibilities.

See this answer for more information if you're interested, but it's rather a thing for library developers etc.

like image 62
unddoch Avatar answered Sep 29 '22 02:09

unddoch