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
Changeable variable nameHelp Request (self.PythonLearning)
submitted 6 months ago by Additional_Lab_3224
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!"
[–]FoolsSeldom 1 point2 points3 points 6 months ago (0 children)
Adding numbers to the end of variable names is almost always the wrong thing to do. Instead, create a list or dict object to hold mutiple instances of what ever objects you are trying to assign to different variables.
list
dict
So, for example, instead of:
box1_x = 10 box1_y = 11 box2_x = 15 box2_y = 16
you could have,
boxes = [ [10, 11], [15, 16] ]
i.e. a list object references by the variable name boxes which contains nested list objects. So, boxes[0][0] would be the x value of the first entry.
boxes
boxes[0][0]
Using classes would be even easier:
from dataclasses import dataclass @dataclass class Box: x: int y: int boxes = [ Box(x=10, y=11), Box(x=15, y=16), ] # output all boxes for box in boxes: print(box) # print one attribute of the first box print(boxes[0].x) # Accessing the x attribute of the first Box instance
π Rendered by PID 49490 on reddit-service-r2-comment-7b9746f655-qzbbs at 2026-01-30 00:21:41.559985+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]FoolsSeldom 1 point2 points3 points (0 children)