【发布时间】:2012-10-16 01:40:25
【问题描述】:
可能重复:
Can I add custom methods/attributes to built-in Python types?
在使用 Python 的过程中,我看到了许多可以用于字符串的东西,例如 .lower() 或 .startswith() 或 .endswith(),但是,我不确定如何制作与它类似的函数,就像我所做的那样想到将不得不使用一个将字符串传递给函数的类,而我只想做类似"the string".myfunc()而不是MyClassObjWithString.myfunc()的事情。
有没有办法实现这样的功能?
【问题讨论】:
标签: python function python-2.7