python nested classes

后端 未结 3 636
甜味超标
甜味超标 2020-12-29 07:17

First of all, here\'s my test code, I\'m using python 3.2.x:

class account:
    def __init__(self):
        pass

    class bank:
        def __init__(self):         


        
3条回答
  •  庸人自扰
    2020-12-29 08:00

    There are several problems:

    1. You're using the name balance for both the data member and for the function.
    2. You're missing a return statement in balance().
    3. balance() operates on an instance of bank. There is no instance in a.bank.balance: here, a.bank refers to the inner class itself.

提交回复
热议问题