Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图修改 Python 中“int”类型的行为。
它说
'__new__' is readonly.
有没有办法做到这一点?
谢谢。
您不能修改内置类型,但可以从中派生:
class MyInt(int): def __new__(cls, *args): # whatever