Python method chaining

Write this article from the reasons that a friend said the following code can not understand.

choice = raw_input (“Please enter: \ n”). strip () [0] .lower ()

Many of the experienced programmers, these are not things,

But for beginners, to see such a grammar head a bit big.

This is actually the concept of object-oriented method chain.

See Wikipedia definition of the method chain

Method chaining, also known as named parameter idiom,   
is a common syntax for invoking multiple method calls
in object-oriented programming languages.
Each method returns an object, allowing the calls
to be chained together in a single statement without requiring
variables to store the intermediate results.
Local variable declarations are syntactic
sugar because of the difficulty humans have with deeply nested method calls.
A method chain is also known as a train wreck due to the increase
in the number of methods that come one after another in the same
line that occurs as more methods are chained together
even though line breaks are often added between methods.

Specifically in python, see the analysis of the brotherhuang:

Some python beginners on the python method is not very clear call, like a fog like a flower.

python everything is the object, the object calls its method, if the return value, the return value is the object,

This return value also has a method, of course, you can use the point number to call its method,

So go on, is the python method chain call also.

How to design method chain python code

# coding:utf-8
"""
如何通过学习python学会编程
https://github.com/pythonpeixun/article/blob/master/python/how_to_learn_python.md
黄哥python远程视频培训班
https://github.com/pythonpeixun/article/blob/master/index.md
黄哥python培训试看视频播放地址
https://github.com/pythonpeixun/article/blob/master/python_shiping.md
黄哥python培训 咨询qq:1465376564
"""


class Person(object):
"""方法链小sample"""

def name(self, value):
self.name = value
return self # 返回实例对象自己才能再调用实例对象的方法。

def work(self, value):
self.working = value
return self

def introduce(self):
print "你好, 我的名字:", self.name, ",我的工作:", self.working, ",教初学者学会编程!"

person = Person()
person.name("黄哥").work("黄哥python培训").introduce()

php方法链代码

<?php
/*
黄哥php培训 咨询qq:1465376564
https://github.com/pythonpeixun/article/blob/master/php_education.md
*/


class Person{
public $name;
public $working;

public function setName($value){
$this->name = $value;
return $this;
}

public function work($value){
$this->working = $value;
return $this;
}

public function introduce(){
echo "你好, 我的名字:".$this->name.",我的工作:".$this->working.",教初学者学会编程!\n";
}
}

$person = new Person();
$person->setName("黄哥")->work("黄哥php培训")->introduce();
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.