1 链式调用(jq),用python实现链式调用(对象.hello.world.add())
class Person:
def hello(self):
print('hello')
return self
def world(self):
print('world')
return self
def helloworld(self):
print('helloworld')
return self
p = Person()
a = p.hello().world().helloworld()
直接. 不加括号调用
class Person:
@property
def hello(self):
print('hello')
return self
@property
def world(self):
print('world')
return self
@property
def helloworld(self):
print('helloworld')
return self
p = Person()
a = p.hello.world.helloworld
2 关键字过滤的标签
str1 = input('输入信息:')
res = str1.replace('卧槽', '爱国').replace('牛批', '敬业').replace('草泥马', '诚信').replace('TMD', '友善')
print(res)