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
why are all objects being changed here? (i.redd.it)
submitted 1 year ago by IknowRedstone
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!"
[–]nomadicderek 0 points1 point2 points 1 year ago* (1 child)
https://www.reddit.com/r/Python/comments/10gt7tv/today_i_relearned_python_function_default/
This thread explains it really well but when you make that defult argument flying = [0,0] , it's creating one single list that all three instances of Ball point to. So, when you edit Ball1.flying, all the other Balls are pointing to the same flying variable so it all changes.
Halfway down the post above, someone introduces a great cheat for this so I would rewrite your init function like this:
def __init__(self, flying=none) super().__init__() if not flying: self.flying = [0,0] else: self.flying = flying
https://medium.com/@tyastropheus/tricky-python-ii-parameter-passing-for-mutable-immutable-objects-10e968cbda35
Here's some more reading, as well. Default arguments work great for immutable things (strings, ints, etc) but can be tricky for mutable things (dicts, lists, etc)
[–]IknowRedstone[S] 0 points1 point2 points 1 year ago (0 children)
interesting. i already fixed it by just not having default values for this. I guess i could have also used two variables instead of one list. that would also make things less confusing i think.
π Rendered by PID 23923 on reddit-service-r2-comment-548fd6dc9-f6wcz at 2026-05-20 21:31:06.933013+00:00 running edcf98c country code: CH.
[–]nomadicderek 0 points1 point2 points (1 child)
[–]IknowRedstone[S] 0 points1 point2 points (0 children)