What is method chainining in Python and how to do it
Hello Pythoners,
In this video we will learn what is method chainning in Python and how to do it.
Some time you will found a statement like this: john.sayName().sayHello() and confuse what is type of statement is this?
Well, it is named a chainned method; methods of an object that call one after the other.
The main ingerdients is: return self statement in each of the method that you want to able to chainned call, in this case sayName() method and sayHello() method, both will have return self statement in the method definition.
There are times when you forget to write a return self statement in one of your method definition that you want to chainned and when you involve that method on your chainned method, it is still working. It is still working only when that forgotten method is put last or invoked last in the chainned method. So, the best way, is to put return self statement in all of you method definition.