python中的函数和方法区别

 在类中定义的函数叫方法

class Person :
    def say_hello(self) :
        print('你好!我是 %s' %self.name)
# 创建Person的实例
p2 = Person()
print(p2.name)

普通方法叫函数

def fn5(a , b):
    return a + b
print(fn5(10,30))

猜你喜欢

转载自blog.csdn.net/dubo_csdn/article/details/84993085