在python中实现链式调用只需在函数返回对象自己就行了。

 1 class Person:
 2     def name(self, name):
 3         self.name = name
 4         return self
 5 
 6     def age(self, age):
 7         self.age = age
 8         return self
 9 
10     def show(self):
11         print "My name is", self.name, "and I am", self.age, "years old."
12 
13 p = Person()
14 p.name("Li Lei").age(15).show()

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-09
  • 2021-07-27
  • 2022-12-23
  • 2021-10-08
  • 2023-01-29
猜你喜欢
  • 2022-12-23
  • 2021-09-30
  • 2022-12-23
  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案