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

  • Home
  • SEARCH
  • 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 6797929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:40:09+00:00 2026-05-26T18:40:09+00:00

I defined such simple class as below: >>> class myclass(object): name = google And

  • 0

I defined such simple class as below:

>>> class myclass(object):
    name = "google"

And I am creating an instance to call name attribute

>>> a = myclass()
>>> a.name
'google'

and also calling it directly from the class itself.

>>> myclass.name
'google'

So far (as I am having background with C# and Java) I will call myclass.name static invocation and calling static members from instances are fine.

But what I am observing is till I set a.name with another value, changing myclass.name is also affecting a.name. Once I set a.name, changing myclass.name doesn’t affect the a.name any more and they begin to have different values.

You can see the whole experiment below:

>>> class myclass(object):
    name = "google"


>>> myclass.name
'google'
>>> a = myclass()
>>> a.name
'google'
>>> myclass.name = "yahoo"
>>> a.name
'yahoo'
>>> myclass.name = "hello world"
>>> a.name
'hello world'
>>> myclass.name
'hello world'
>>> myclass.name = "another trick"
>>> myclass.name
'another trick'
>>> a.name
'another trick'
>>> a.name = "I changed the value of a"
>>> a.name
'I changed the value of a'
>>> myclass.name
'another trick'
>>> myclass.name = "changed again"
>>> a.name
'I changed the value of a'

I would like someone to explain the reason behind this behavior.

Thanks.

  • 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-26T18:40:10+00:00Added an answer on May 26, 2026 at 6:40 pm

    I took a look at Python Data Model documentation. If you skip ahead to “Class instances” section, you will see the crucial explanation:

    Attribute assignments and deletions update the instance’s dictionary,
    never a class’s dictionary.

    So in your example, when you do a.name = ..., you introduce a new key name into a’s __dict__. After that when you access name attribute, the standard attribute lookup mechanism looks into a’s __dict__ first.

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

Sidebar

Related Questions

i would like to create a new object in javascript (using simple inheritance) such
Why was java defined such that methods may take as input multiple parameters, but
I'm using script language ChaiScript with c++ and Qt. I've defined such function: void
I have an Enum called Status defined as such: public enum Status { VALID(valid),
I've got an enum defined as such: Private Enum AllowedMonthNumbers _1 _2 _3 _4
I'm using a jQuery plugin that has its functions defined as such: $('#mydiv').pluginAction({ someproperty:
I noticed methods marked optional in several protocols defined in the iPhone SDK, such
Cocos2D defines the static method 'actions' for the Sequence class as such: +(id) actions:
I have a class, for experiment sake call it foo() and another class, call
Having the following simple class structure: class A { } class B extends A

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.