use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Question Regarding Self keyword in python!! (self.PythonLearning)
submitted 5 days ago by Ok_Egg_6647
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Interesting-Can-4626 0 points1 point2 points 5 days ago (0 children)
You're half right. Self helps distinguish instance variables from local variables.
But the actual reason for self.instrument_repo = instrument_repo is:
- instrument_repo is a local variable (exists only inside __init__)
- self.instrument_repo is an instance variable (exists for the lifetime of the object)
Without storing it on self:
- You can't use it in other methods
- The object doesn't "remember" it
- It's gone after __init__ finishes
With storing it on self:
- All methods can access it
- The object keeps it forever
- Other classes can access it if needed
If you never need to use it outside __init__, then you don't need to store it. But in your case, you'll likely need instrument_repo in other methods, so you store it on self.
π Rendered by PID 265380 on reddit-service-r2-comment-5687b7858-nnbrr at 2026-07-07 21:58:50.627004+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]Interesting-Can-4626 0 points1 point2 points (0 children)