84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
比如内置类str,有个方法strip().我想修改strip()这个方法的参数和实现.那我该怎么做呢?如果不可以修改,那是否可以给内置类添加一个自定义的方法呢?如果可以,最好请给个简单的示例.多谢您的回复!
class laplace(str): def strip(self, chars=None, string='sorry'): return 'something %s' % string x = laplace() print x.strip()
Is this the effect you want by inheriting str and overriding the parent class method?
Python can directly overload, that is to say, you can implement a new strip function on the subclass, so that it is covered.
Is this the effect you want by inheriting str and overriding the parent class method?
Python can directly overload, that is to say, you can implement a new strip function on the subclass, so that it is covered.