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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:25:49+00:00 2026-06-16T13:25:49+00:00

I am not a complete beginner but fairly new to Python . Whilst working

  • 0

I am not a complete beginner but fairly new to Python. Whilst working on a project today I just had an idea and wondered regarding the usage of “self“; about which I’ve been reading for the past some while and I still can not figure out if it’s always necessary or not. My question solely concerns instances of classes and instance parameters/variables. This question is not about Class Variables which affect all instances.

Example:

class C:
    def __init__(self, parent = None):
        super(C, self).__init__(parent)
        self.some_temp_var = AnotherClass()
        self.important_property = self.some_temp_var.bring_the_jewels()

ins_c = C()
print ins_c.important_property 

In the above code, I use self before both variable declarations (some_temp_var and important_property).

I will need to access **important_property** later from the outside (where instance’s been created) and maybe even modify it.

But I will not need access to the instance of AnotherClass() and/or variable pointing to it (some_temp_var). I just need an instance of it class once, and I need to execute its method bring_the_jewels only once to populate value of important_property.

Should I still use self before declaring that variable as well?

self.some_temp_var = ....
self.important_property = ....

or can it be:

some_temp_var = ....
self.important_property = ....

Thank you for your help.

Ps. I did my research in a length way. Due to lack of my English and/or CS knowledge, I may not have found a currently existing duplicate however I did search and I did search a lot. Before calling this question “duplicate” or “not constructive” please read it throughly. This is a question with clear answer and it’s very important, and complicated matter. Thank you for your understanding.

  • 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-16T13:25:50+00:00Added an answer on June 16, 2026 at 1:25 pm

    If you dont use self.some_temp_var, then you are defining a local variable which will be garbage collected after the constructor.

    So yes you need self if you want to define an instance attribute that should persist with the instance. Whether you need it to be public or private is a matter of naming. Prefix it with an _ for protected or __ for private.

    If some_temp_var is just a temp for the constructor and you never need it again then no, you dont need self. It is about persistence and member attributes. You do not need self for the pure fact of working with a variable within a single method.

    Consider this… What if some_temp_var were some huge data structure that you build up to arrive at the real result value? You dont want to use self to store a temp variable because it wont free memory until you delete it or the instance. You want it to be cleaned up when it is no longer needed.

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

Sidebar

Related Questions

I have a mysql problem, my query looks as follows but not complete SELECT
I've seen a number of posts on UIGetScreenImage, however, not a complete working (short)
I'm not sure if this is possible (complete non-flash developer speaking), but we have
I just read in Code Complete that you should not use exceptions for flow
Can anyone recommend a good matplot tutorial. I am a complete beginner - but
I currently have a small (I'm a complete beginner) project in VTK where I've
I have created a mobile app using Phonegap Build (not just Phonegap...but Build ).
I'm a complete beginner when it comes to ASP.NET but I want to learn
This is a rather broad question, but I'm a beginner-intermediate programmer that has just
I have found answers to question like this one helpful but not complete for

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.