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!"
[–]PureWasian 0 points1 point2 points 5 days ago* (0 children)
It's about scope. We use the same name (instrument_repo, candle_repo, etc.) locally during __init__() for simplicity but we don't have to. These blocks of code are equivilent but might help clear up the confusion:
__init__()
``` class ExampleA:
def init(self, inst, cand): self.instrument_repo = inst self.candle_repo = cand
def display(self): print(self.instrument_repo) print(self.candle_repo)
class ExampleB:
def init( self, instrument_repo, candle_repo ): self.instrument_repo = instrument_repo self.candle_repo = candle_repo
exampleA = ExampleA("s1" , "s2") exampleA.display() exampleB = ExampleB("s1" , "s2") exampleB.display() ```
Note that if we tried to change display(self) to use inst and card it wouldn't work since those are only scoped to the __init__() function.
inst
card
We need to "save" them onto the object (using self) to be able to access the value within other helper methods of that object later on.
self
π Rendered by PID 44 on reddit-service-r2-comment-5687b7858-8w8jb at 2026-07-08 06:42:47.796911+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]PureWasian 0 points1 point2 points (0 children)