python-function

  1. 普通函数(未定位在类里),都是函数。
  2. 静态方法(@staticmethod),都是函数。
  3. 类方法(@classmethod),都是方法。
  4. 实例方法(首参数为self且非静态、非类方法的),都是方法。
def spam(a, b=42):
print(a, b)
spam(1) # Ok. a=1, b=42
spam(1, 2) # Ok. a=1, b=2

# Using a list as a default value
def spam(a, b=None):
if b is None:
b = []
...

Function Annotations