[Python 进阶]python 实现链式调用
#!/usr/bin/env Python3
# -*- coding: utf-8 -*-
# @Software: PyCharm
# @virtualenv:workon
# @contact: 1040691703@qq.com
# @Desc:python实现链式调用
# 在python中实现链式调用只需在函数返回对象自己就行了。
__author__ = '未昔/AngelFate'
__date__ = '2020/5/31 19:58'
class Person(object):
def name(self, name):
self.name = name
return self
def age(self, age):
self.age = age
return self
def show(self):
print("My name is", self.name, "and I am", self.age, "years old.")
p = Person()
p.name("wangwei").age(15).show()
My name is wangwei and I am 15 years old.
Process finished with exit code 0
python 实现链式调用