python向内置类型添加新方法

beo*_*ver 2 python function chaining

我如何编写可附加到字符串(或其他对象)的python函数?

例如:

"FOO".lower()
Run Code Online (Sandbox Code Playgroud)

他们如何收到投入?他们是发电机吗?

我会高兴地读到它,但我真的不知道我在寻找什么.

Thi*_*ter 6

字符串是对象,因此有方法.lower()是其中之一.

你不能添加自定义方法str,unicode或任何其他内置(用C语言编写)类 - 请参阅实现自定义字符串方法在python中扩展内置类