Python Class Members Initialization

前端 未结 5 1762
后悔当初
后悔当初 2020-11-29 03:37

I have just recently battled a bug in Python. It was one of those silly newbie bugs, but it got me thinking about the mechanisms of Python (I\'m a long time C++ programmer,

5条回答
  •  隐瞒了意图╮
    2020-11-29 04:37

    Pythons class declarations are executed as a code block and any local variable definitions (of which function definitions are a special kind of) are stored in the constructed class instance. Due to the way attribute look up works in Python, if an attribute is not found on the instance the value on the class is used.

    The is an interesting article about the class syntax on the history of Python blog.

提交回复
热议问题