Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:13:14+00:00 2026-06-18T01:13:14+00:00

First of all, here’s my test code, I’m using python 3.2.x: class account: def

  • 0

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):
            self.balance = 100000

        def balance(self):
            self.balance

        def whitdraw(self, amount):
            self.balance -= amount

        def deposit(self, amount):
            self.balance += amount

when I do:

a = account()
a.bank.balance

I expected to get the value of balance returned, instead I get the function “balance”, why is this? It returns the value of balance when I do:

class bank:
    def __init__(self):
        self.balance = 100000

    def balance(self):
        self.balance

    def whitdraw(self, amount):
        self.balance -= amount

    def deposit(self, amount):
        self.balance += amount

a = bank()
a.balance

So I want to know why this is and it would be great if someone could come up with a way to give me the value of balance in the nested version.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:13:15+00:00Added an answer on June 18, 2026 at 1:13 am

    My version of your code, with comments:

    #
    # 1. CamelCasing for classes
    #
    class Account:
        def __init__(self):
            # 2. to refer to the inner class, you must use self.Bank
            # 3. no need to use an inner class here
            self.bank = self.Bank()
    
        class Bank:
            def __init__(self):
                self.balance = 100000
    
            # 4. in your original code, you had a method with the same name as 
            #    the attribute you set in the constructor. That meant that the 
            #    method was replaced with a value every time the constructor was 
            #    called. No need for a method to do a simple attribute lookup. This
            #    is Python, not Java.
    
            def withdraw(self, amount):
                self.balance -= amount
    
            def deposit(self, amount):
                self.balance += amount
    
    a = Account()
    print(a.bank.balance)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, here's the code: public class Test{ public static void main(String args[]){
First of all, here's the code: def check_sudoku(n): d=len(n) i=0 s=1 while i<d: print
First of all here is my code so that you can test it to
First of all here are some code snippets: public void startThread() { this.animationThread =
First of all, here is the basic code for the site I need help
first of all here is my situation. I am programming an intranet application using
First of all, here is my code snippet: var str = '<!--:de-->some german text<!--:--><!--:en-->some
first of all here is my code: @protocol SearchTableViewControllerDelegate @required - (void)didSelectFileCardsContent:(FileCardsContent*)content; @end @interface
First of all, I'm new to programming and python, I've looked here but can't
First of All here's the Codes: Product Information: public class ProductInformation { public String

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.