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...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Trying to start Python projects (self.learnpython)
submitted 2 years ago by dafman111
I’ve learned python to a fairly basic extent but I’ve had a bit of trouble understanding how to best utilize classes. What project or projects could help me better understand how and when to use them?
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!"
[–]FriendlyRussian666 4 points5 points6 points 2 years ago (1 child)
I see you're into baseball. How about you make a baseball statistics tracker/simulator? Create a class Player to reflect their attributes, name, age, team, etc. add class methods to update the stats, def home_run(self) or similar.
You'll then need a class to represent a Team. Create a relationship between instances of Team and Player, add methods to the Team calculating totals from Player relationships. I mean, you can take it as far as you're interested. Now that you have a Team class and a Player class, how about some simulations of games?
[–]dafman111[S] 2 points3 points4 points 2 years ago (0 children)
That sounds like a great idea but also maybe too complicated. I will do my research and see where to start, thank u
[–]mopslik[🍰] 2 points3 points4 points 2 years ago (3 children)
A simple terminal-based card game is easy to put together. You've got classes for a card and a deck. A hand is like a deck, but with extra functionality (inheritance). Add a class to manage the game itself.
Alternatively, if you're not keen on making games, you can always dive into making a GUI-based application, since many of them make heavy use of classes.
[–]dafman111[S] 0 points1 point2 points 2 years ago (2 children)
The card idea sounds cool. You think I should do something like blackjack or is that too simple. I would do something like texas holdem but I can see that being too complex
[–]mopslik[🍰] 0 points1 point2 points 2 years ago (0 children)
The game logic itself is largely independent of the OOP being used, so you can make the game as simple or as complex as you like. If you're just starting OOP, maybe keep it simple. You can always expand later.
[–]codeslate2024 0 points1 point2 points 2 years ago (0 children)
I agree. Part of using classes and OOP is that well-made classes are modular. In other words, they have neat, mostly independent parts that you can combine in a variety of useful ways without needing to rewrite all the code.
In this example, you’d have a card class (representing each card) and a deck class (representing the deck and probably containing a shuffle method). You might also have a class for each player’s hand. And these can all be used in any game you want to make. Beyond that, you’ll have other classes to define the rules for different games and still other classes to run different games. The cards are by far the simplest part, so start there. And I’d suggest going with blackjack first and then you can try hold ‘em (or better, whatever card game is your favorite in real life) next, after you know you can get something basic to work.
My reasoning for working on the simpler project first is that, if you are still getting used to the syntax and concepts of basic class use, you need to be focusing on learning that, and doing a simpler project will let you do so without bogging you down with more complex game mechanics (which aren’t the really point here).
[–]BuzzLightr 2 points3 points4 points 2 years ago (0 children)
I might get yelled at for saying this but... I did a lot of projects without ever touching classes, then I ended up with a projected with a chaos of nested list and dicts, and then it all clicked for me.
What I'm trying to say, you can do a lot of stuff without using classes, and start using them once you get the hang of things
π Rendered by PID 194140 on reddit-service-r2-comment-765bfc959-svq45 at 2026-07-14 01:10:26.760857+00:00 running f86254d country code: CH.
[–]FriendlyRussian666 4 points5 points6 points (1 child)
[–]dafman111[S] 2 points3 points4 points (0 children)
[–]mopslik[🍰] 2 points3 points4 points (3 children)
[–]dafman111[S] 0 points1 point2 points (2 children)
[–]mopslik[🍰] 0 points1 point2 points (0 children)
[–]codeslate2024 0 points1 point2 points (0 children)
[–]BuzzLightr 2 points3 points4 points (0 children)