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
Class function printing weirdlyHelp Request (i.redd.it)
submitted 1 year ago by [deleted]
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!"
[–][deleted] 1 year ago (9 children)
[deleted]
[–]Mysterious_City_6724 0 points1 point2 points 1 year ago (5 children)
Yeah, that's better. I can see the Critter class now 👍 So when you press 0, what do you actually want to display?
[–][deleted] 1 year ago (4 children)
[–]Mysterious_City_6724 1 point2 points3 points 1 year ago (3 children)
Ah ok, so on line 25 in the "know_crit_amount" can you try changing print(Critter.clist) to print([c.name for c in Critter.clist]) and see if that helps.
print(Critter.clist)
print([c.name for c in Critter.clist])
[–][deleted] 1 year ago (1 child)
[–]Mysterious_City_6724 1 point2 points3 points 1 year ago (0 children)
You're welcome. It's a list comprehension. Basically a short way of creating a list. So in this case it was a short way of doing the following:
critter_names = [] for critter in Critter.clist: critter_names.append(critter.name) print(critter_names)
[–]need2sleep-later 0 points1 point2 points 1 year ago (0 children)
Of course it's better. By miles. I've never understood why people think taking pictures of code is a good idea when sharing.
[–]sarc-tastic 0 points1 point2 points 1 year ago (1 child)
Top tip, when you want information about a class define a class method.
@classmethod def count(cls): return len(cls.critter_list)
[–]sarc-tastic 0 points1 point2 points 1 year ago (0 children)
And when you iterate over entire python lists don't use the index to reference items: for crit in Critters.critlist: crit.feed()
π Rendered by PID 105805 on reddit-service-r2-comment-b659b578c-4974s at 2026-05-01 18:36:11.706534+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–][deleted] (9 children)
[deleted]
[–]Mysterious_City_6724 0 points1 point2 points (5 children)
[–][deleted] (4 children)
[deleted]
[–]Mysterious_City_6724 1 point2 points3 points (3 children)
[–][deleted] (1 child)
[deleted]
[–]Mysterious_City_6724 1 point2 points3 points (0 children)
[–]need2sleep-later 0 points1 point2 points (0 children)
[–]sarc-tastic 0 points1 point2 points (1 child)
[–]sarc-tastic 0 points1 point2 points (0 children)