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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:29:41+00:00 2026-06-08T09:29:41+00:00

I am quite new to Python and I cant seem to be able to

  • 0

I am quite new to Python and I cant seem to be able to understand this.Consider this simple Python code.

class point:
   i = 34


test = point()
test.y = 45

print test.y 

As you can see I instance of point called test but then did test.y = 45 when y is not a
data member of the point class. No error was thrown and the y attribute seems to have
been added to the class automatically.

Why did this happen? Isn’t this a misfeature? Or am I missing something very basic.
The same thing cannot be done with C++ and it would throw a compiler error. Any reason for this strange feature?

  • 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-08T09:29:42+00:00Added an answer on June 8, 2026 at 9:29 am

    It is just a common thing from scripting languages. Python lets you do it, Ruby also, and in deed, you never had to pre-define your local variables. Why not also in your classes? Not only that, you can choose if the new inserted variables/functions affect only one object or all instances of that class.

    People who are doing heavy things in TDD and UnitTesting love that misfeature. Actually I would even go as far as to say that C++ static typing does not reduce my programs bugs nearly as much as a language that ease my unit tests giving me exactly that.

    However, if you are concerned, you can always use _____slots_____

    https://stackoverflow.com/a/3603624/253098

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

Sidebar

Related Questions

I am quite new to python programming (C/C++ background). I'm writing code where I
Still quite new to Python. I have a problem similar to this question .
I'm creating a game, and am quite new to Python generally. I created a
I'm quite new to CSS / HTML, and can't find the cause of this
i am quite new in python. I am receiving (through pyserial) string with data
I'm quite new to python, so I'm doing my usual of going through Project
I'm quite new to threading in Python and have a couple of beginner questions.
i am quite new to python.subprocess() if i folk a new process from python,
I am quite new in Python programming. While googling I found some of the
I am quite new in python.I want to match string in some lines of

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.