Class Variable behaving like Instance Variable (Python 3.4)

前端 未结 3 587
别跟我提以往
别跟我提以往 2021-01-21 21:03

Python 3.4.0a1
Windows 8.1

Class Created:

class Bank(object):  
    bankrupt = False  

Command entered in IDLE __main__

3条回答
  •  日久生厌
    2021-01-21 21:27

    With b.bankrupt = True you create an instance variable that shadows the class-level variable.

    If you want to change the class variable use

    Bank.bankrupt = True
    

提交回复
热议问题