1. 类的定义

Python2中需要继承object

  1. # 默认, Python 3
  2. class A:
  3. pass
  4. # Python 2
  5. class A(object):
  6. pass

super

  1. # 默认,Python 3
  2. class B(A):
  3. def add(self, x):
  4. super().add(x)
  5. # Python 2
  6. class B(A):
  7. def add(self, x):
  8. super(B, self).add(x)