Combining Methods &it is a method that is used to make multiple method calls on the same object using an object reference only once. Example:
Suppose we have a Foo class that has two methods, bar and baz.
We create an instance of the Foo class:
foo = Foo ()
No method chaining to call and bar, and baz, for the foo object, we do this:
foo.bar () foo.baz ()
With method chaining we do this:
Chaining both the bar () and baz () methods for foo.
foo.bar (). baz ()
Simple method chaining can be easily implemented in Python.
class Foo (object): def bar (self): print "Foo.bar called" return self def baz (self): print "Foo.baz called" return self foo = Foo () foo2 = foo.bar (). baz () print "id (foo):", id (foo) print "id (foo2 ): ", id (foo2)
Here is the result of running the above program:
Foo.bar called Foo.baz called id (foo): 87108128 id (foo2): 87108128
The series “Studies in Big Data” (SBD) publishes new developments and advances in the various areas of Big Data-quickly and with a high quality. The intent is to cover the theory, research, develo...
Executing Data Quality Projects: Ten Steps to Quality Data and Trusted Information (TM), 2nd Edition. Execute Data Quality Projects, Second Edition presents a structured yet flexible approach to cr...
Pandas for Everyone: Python Data Analysis (Addison-Wesley Data & Analytics Series), 1st Edition. Pandas for Everyone brings together the practical knowledge and insights you need to solve real-worl...
A Practical Approach to Computer Algorithms Using Python® and C# Rod Stephens started out as a mathematician, but while studying at MIT, he discovered how much fun algorithms are. He took every al...