zoukankan      html  css  js  c++  java
  • 类和函数的区别

    类外面: ---- 函数

    类里面
      取决调用者
      类.func(xx) ---- 函数
      对象.func() ----方法

    可以使用 MethodType, FunctionType来判断:

    from types import MethodType, FunctionType
    
    
    class A:
    
        def func(self):
            return 123
    
    
    print(isinstance(A.func, MethodType))       # False
    print(isinstance(A.func, FunctionType))     # True          类调用,是函数
    
    a = A()
    
    print(isinstance(a.func, MethodType))       # True          对象调用, 是方法
    print(isinstance(a.func, FunctionType))     # False
    复制代码
  • 相关阅读:
    hdu 1286
    hdu 1420
    hdu 2068
    hdu 1718
    hdu 1231
    hdu 1072
    HDOJ 350留念
    hdu 1898
    hdu 1593
    帮助理解git的图
  • 原文地址:https://www.cnblogs.com/jin-yuana/p/10024988.html
Copyright © 2011-2022 走看看