Questions tagged «built-in-types»



7
我可以将自定义方法/属性添加到内置Python类型吗?
例如,例如我想helloWorld()向Python的dict类型添加一个方法。我可以这样做吗? JavaScript具有这种行为的原型对象。也许这是错误的设计,我应该将dict对象子类化,但随后它只能在子类上工作,而我希望它在将来的所有字典中都可以使用。 这是在JavaScript中的用法: String.prototype.hello = function() { alert("Hello, " + this + "!"); } "Jed".hello() //alerts "Hello, Jed!" 这是带有更多示例的有用链接-http ://www.javascriptkit.com/javatutors/proto3.shtml
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.