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 7001083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:45:26+00:00 2026-05-27T20:45:26+00:00

Dictionaries and lists defined directly under the class definition act as static (e.g. this

  • 0

Dictionaries and lists defined directly under the class definition act as static (e.g. this question)
How come other variables such as integer do not?

>>> class Foo():
        bar=1

>>> a=Foo()
>>> b=Foo()
>>> a.bar=4
>>> b.bar
1
>>> class Foo():
        bar={}

>>> a=Foo()
>>> b=Foo()
>>> a.bar[7]=8
>>> b.bar
{7: 8}
  • 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-05-27T20:45:27+00:00Added an answer on May 27, 2026 at 8:45 pm

    They are all class variables. Except for when you assigned a.bar=4 creating an instance variable. Basically Python has a lookup order on attributes. It goes:

    instance -> class -> parent classes in MRO order (left to right)
    

    So if you have

    class Foo(object):
        bar = 1
    

    This is a variable on the class Foo. Once you do

    a = Foo()
    a.bar = 2
    

    you have created a new variable on the object a with the name bar. If you look at a.__class__.bar you will still see 1, but it is effectively hidden due to the order mentioned earlier.

    The dict you created is at the class-level so it is shared between all instances of that class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With lists of dictionaries such as the following: user_course_score = [ {'course_id': 1456, 'score':
I've been having a problem with making sorted lists from dictionaries. I have this
I need to store Python structures made of lists / dictionaries, tuples into a
I have a web API that returns python dictionaries or lists as a response
So lets say I have an incredibly nested iterable of lists/dictionaries. I would like
Is there any performance advantage to using lists over dictionaries over tuples in Python?
In Python, I've got a list of dictionaries that looks like this: matchings =
Skip lists (Pugh, 1990) provide sorted dictionaries with logarithmic-time operations like search trees but
I have two lists of dictionaries list1 = [ {..}, {..}, ..] list2 =
I have two lists of test results. The test results are represented as dictionaries:

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.