Discuss / Python / 疑问

疑问

Topic source

三桥墨

#1 Created at ... [Delete] [Delete and Lock User]

parser.StartElementHandler = handler.start_element 这一句里,一个类的函数直接等于(或者赋值)另一个类的函数,这个要怎么理解,原理过程是怎么样的??

三桥墨

#2 Created at ... [Delete] [Delete and Lock User]

查了些东西觉得是回调函数,但是这个直接用等号的格式或者说语法是怎么一回事呢,有谁懂哇

廖雪峰

#3 Created at ... [Delete] [Delete and Lock User]

回头看 “函数式编程”

相当于把右边类的method 传递给左边的。 class ffn(object): def f (self,x,y): return x+y

class f(object): def ff(self,x,y): return x-y pass a=ffn() b=f() print(b.ff(2,1))#输出为1 print(isinstance(b,f))#是f的instance f.ff=a.f print(type(f))#仍旧是class print(f.ff(2, 1)) # 输出为,ff method 已经被替换成了ffn的ff了


  • 1

Reply