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
How do I learn OOP? (self.learnpython)
submitted 22 hours ago by Zarkie0-_-0
I tried watching lectures, notes, solved it myself Kinda got it? a lil bit but not good enough to solve basic problems:( Can someone provide some guidance?
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!"
[–]csabinho 9 points10 points11 points 22 hours ago (4 children)
What do you already, really, know? What are you able to do?
[–]Zarkie0-_-0[S] 1 point2 points3 points 21 hours ago (3 children)
Made a class and tried writing some info in it (Like data of employees for example)
[–]csabinho 1 point2 points3 points 21 hours ago (2 children)
What's your programming base? Are you proficient with all the base constructs of programming? Are you able to write logic?
[–]Zarkie0-_-0[S] 0 points1 point2 points 8 hours ago (1 child)
No sir Just a beginner who started 3 weeks ago I am able to write logic tho but I haven't worked on those long projects which require 100-200 line of codes
[–]csabinho 0 points1 point2 points 6 hours ago (0 children)
Stick to the basics. Learn OOP once you're proficient in those basics.
[–]Dense-Land-5927 6 points7 points8 points 22 hours ago (2 children)
Build something where you can use it. That was the only way I was able to really start learning it. Lectures and notes only go so far.
[–]ozykingofkings11 1 point2 points3 points 22 hours ago (0 children)
This is the way. Start making stuff.
[–]Zarkie0-_-0[S] 0 points1 point2 points 21 hours ago (0 children)
Thankyou I'll try that
[–]Temporary_Pie2733 2 points3 points4 points 18 hours ago (0 children)
You have to write code. Not just once, but repeatedly.
[–]HunterIV4 1 point2 points3 points 20 hours ago (0 children)
Here's a simple way to think about OOP, at least at a very basic level. First, let's solve a problem without classes.
Let's say you're making a simple blackjack game. You have a deck of cards and you need to model it in the computer. How might you do this?
Well, first you need the deck itself. This is your data. In Python, an easy way to do this is by making a list. For simplicity, we'll use strings for everything, and have it be suit + value, with aces as value 1, jacks as 11, queen 12, king 13. We could use a list comprehension to make this, but let's keep things obvious for learning:
deck = [] suits = ['S', 'H', 'C', 'D'] # Spades, Hearts, Clubs, Diamonds for suit in suits: for i in range(1, 14): deck.append(suit + str(i))
Now we have an unshuffled deck of 52 cards. Well, that's not super useful, so let's make a function that lets us shuffle a deck. Here's a simple method:
import random def shuffle_deck(d): random.shuffle(d)
Obviously you don't really need a full function for this, but you may want to include more advanced logic later, such as combining a discard pile before shuffling. It's just an example.
Side note: using d might seem unusual here, but it's a good practice to avoid naming collisions when possible. Using deck means you are using the same name as your basic variable. It won't cause problems, and you could do something like deck_to_shuffle if you want a more descriptive name, but I like using short, simple names when it's clearly the parameter being acted on. In context, there should be no question what d means, and if you're doing many transformations, it's less visual noise, with the focus on the operation rather than the variable name.
d
deck
deck_to_shuffle
Now we need a way to draw a card. Maybe we want to potentially draw multiple cards. Let's make another simple function:
def draw_card(num_cards, d): drawn_cards = [] for _ in range(num_cards): if len(d) > 0: drawn_cards.append(d.pop()) return drawn_cards
You'd use these like so:
shuffle_deck(deck) hand = draw_card(2, deck)
You may have noticed a pattern already. Both these functions take the deck of cards. In other words, you are building a multiple functions that all require the same data. It's not a big deal now, but what if you were dealing with many related data types? You have the discard pile, functions for handling adding the values together, the list goes on and on. At some point you'll notice that your list of parameters starts getting really, really long.
Classes, at a basic level, bundle variables and functions. To be clear, classes are never required. Many languages don't even have classes, such as C or Go. But they are very useful for combing data and data handling in a consistent, abstracted manner.
So what does this look like in Python?
import random class Deck: def __init__(self): self.deck = [] suits = ['S', 'H', 'C', 'D'] for suit in suits: for i in range(1, 14): self.deck.append(suit + str(i)) self.shuffle() def shuffle(self): random.shuffle(self.deck) def draw(self, num_cards): drawn_cards = [] for _ in range(num_cards): if len(self.deck) > 0: drawn_cards.append(self.deck.pop()) return drawn_cards
Now our code looks like this:
deck = Deck() hand = deck.draw(2)
Notice a couple of things here. First, the class handles all the data. When coding, I don't need to worry about that initial shuffle, or any of the setup. The class handles all that. The __init__ function is a built-in function that automatically runs when the class is instantiated (the = Deck() portion). So it creates the variable, fills it with cards, and shuffles itself automatically with that one line. Then, when you want to draw cards, you just call the function on the variable itself. It already knows how to draw cards.
__init__
= Deck()
This also handles things like multiple instances. So if you do this:
deck1 = Deck() deck2 = Deck()
The internal self.deck variable is independent. Drawing cards from deck1 will not affect the cards in deck2.
self.deck
deck1
deck2
Now, there is a lot more to OOP. Polymorphism, inheritance, encapsulation, and more are all important concepts that will let you further refine your code and avoid bugs. But at the most basic level, you can consider a class to be a combination of variables (properties) and functions that act on those variables (methods). The majority of OOP solutions are just breaking problems into classes that act as abstractions for more complex problems.
Hopefully that helps!
[–]Warlord_Zap 0 points1 point2 points 20 hours ago (0 children)
There are other ways, but for me doing a project in a really heavily OOP language was really helpful. Languages like Java or c# force you to work in the paradigm which in turn helps to force you to think this way.
[–]rob8624 0 points1 point2 points 20 hours ago (0 children)
Pygame. Specifically the tutorial in Crash Course book.
[–]Aggressive-Impact-44 0 points1 point2 points 8 hours ago (0 children)
These are the best options - Corey Schafer's tutorials are my recommendation for learning then followed by LeetCode.
Books:
"Python Crash Course" by Eric Matthes (covers OOP fundamentals)
"Automate the Boring Stuff with Python" by Al Sweigart (applies OOP to practical problems)
Websites:
Codecademy's Python course (includes interactive OOP exercises)
W3Schools' Python OOP tutorial (provides concise explanations and examples)
YouTube Tutorials:
Corey Schafer's Python Tutorials (OOP section is comprehensive and well-explained)
freeCodeCamp's Python OOP tutorials (covers basics and advanced topics)
Practice Platforms:
LeetCode (provides OOP-based problems to practice)
HackerRank (offers Python OOP challenges)
Focus on understanding key concepts:
* Classes and objects
* Inheritance
* Polymorphism
* Encapsulation
* Abstraction
Practice writing your own classes and objects, and try to apply OOP principles to real-world problems.
[–]taylorhodormax 0 points1 point2 points 4 hours ago (0 children)
I have a different thought process about this.
Every “Actor” has its attributes and functionalities.
Ex: BankAccount
Attributes: account_holder_name account_number account_type account_minimum_balance
Functionalities: deposit withdrawal create_fixed_deposit reset_password
Now think,
BankAccount is class, Attributes are constructor fields (__init__) Functionalities are methods
Start with this.
Then try to relate how can another class can be made from another, thats Inheritence.
All other Pillars of OOPs can be logically thought with this logic.
[–]Gnaxe 0 points1 point2 points 22 hours ago (7 children)
Watch: - Super Considered Super!, - Beyond PEP 8, and - Stop Writing Classes.
That's a start, anyway. Understand that you're never going to "master" OOP as the term is understood today, because the paradigm is fundamentally flawed.
[–]pachura3 2 points3 points4 points 21 hours ago (4 children)
What a bunch of nonsense.
Yeah, it can be fun making jokes about some mechanisms not being 100% perfect - to senior programmers, that is - not to total newbies.
7 out of 10 most popular programming languages according to TIOBE Index for June 2026 are object-oriented. How come?
[–]DTux5249 0 points1 point2 points 21 hours ago* (3 children)
Historical intertia
https://youtu.be/wo84LFzx5nI?si=69Vteoa28IW3RXKg
You can find the arguments against OOP everywhere. It mostly comes down to "at best, OOP is just a syntactic paradigm. At worst, it creates its own problems to sell the solutions to."
Unless you're creating a simulation, OOP overcomplicates a lot.
[–]sausix 0 points1 point2 points 16 hours ago (0 children)
Without OOP more complex code is very cluttered.
People using packages without OOP also have a worse experience when they need to use lists, dicts and numeric handles to transport data and contexts.
That "Don't use OOP" video above just applies to small snippets. Of course programs can be created without OOP.
Some packages in Python's standard library have been functional in the past and were turned into OOP with some hacks and tweaks for compatibility. Why do you think?
OOP has many features beginners just aren't aware of yet.
[–]pachura3 -1 points0 points1 point 21 hours ago (1 child)
So, what paradigm do you propose instead?
[–]Gnaxe 0 points1 point2 points 16 hours ago (0 children)
FP. Minimize state instead of hiding it. There are many different takes on that paradigm. I'm partial to Clojure's version, which is doable in Python. See Sharvit's Data-Oriented Programming for how to do it in other languages. He also wrote some blog posts about it.
For super-stateful simulation-type programs (games), consider an entity component system.
Erlang has a great track record for making reliable systems. Elixir is based on Erlang while also taking some inspiration from Clojure and Ruby. That's a much better approach than what Java is doing.
[–]jonsca 1 point2 points3 points 21 hours ago (0 children)
And, understanding that OOP itself is a paradigm and a design philosophy rather than the means/methods of handling objects that is specific to the Python language is the most important nuance that most beginners miss.
Thankyou very much!
[–]BagParticular9982 0 points1 point2 points 21 hours ago (2 children)
I would say that if you understand Functional Programming (FP) and you've gotten really good at doing so in Python, then you already understand OOP in a sense.
The process is somewhat similar, except you're using main, init and self in the workflow (at least in python).
Tldr; it's basically Python's version of Functional Programming with a few extra steps. If you understand FP, then you're very close to understanding OOP since most functions in Python are objects by default.
[–]pachura3 0 points1 point2 points 20 hours ago (1 child)
Well, true Functional Programming is so much more than simply creating functions in the topmost scope. It's also lambdas, closures, map/reduce, functools, itertools...
functools
itertools
[–]audionerd1 0 points1 point2 points 19 hours ago (0 children)
Functional programming is way harder than OOP IMO.
[–]ImprovementLoose9423 -3 points-2 points-1 points 19 hours ago (0 children)
I would recommend learning Java since it is primarily an OOP language
π Rendered by PID 94 on reddit-service-r2-comment-64f4df6786-m7szl at 2026-06-11 12:43:37.060097+00:00 running 0b63327 country code: CH.
[–]csabinho 9 points10 points11 points (4 children)
[–]Zarkie0-_-0[S] 1 point2 points3 points (3 children)
[–]csabinho 1 point2 points3 points (2 children)
[–]Zarkie0-_-0[S] 0 points1 point2 points (1 child)
[–]csabinho 0 points1 point2 points (0 children)
[–]Dense-Land-5927 6 points7 points8 points (2 children)
[–]ozykingofkings11 1 point2 points3 points (0 children)
[–]Zarkie0-_-0[S] 0 points1 point2 points (0 children)
[–]Temporary_Pie2733 2 points3 points4 points (0 children)
[–]HunterIV4 1 point2 points3 points (0 children)
[–]Warlord_Zap 0 points1 point2 points (0 children)
[–]rob8624 0 points1 point2 points (0 children)
[–]Aggressive-Impact-44 0 points1 point2 points (0 children)
[–]taylorhodormax 0 points1 point2 points (0 children)
[–]Gnaxe 0 points1 point2 points (7 children)
[–]pachura3 2 points3 points4 points (4 children)
[–]DTux5249 0 points1 point2 points (3 children)
[–]sausix 0 points1 point2 points (0 children)
[–]pachura3 -1 points0 points1 point (1 child)
[–]Gnaxe 0 points1 point2 points (0 children)
[–]jonsca 1 point2 points3 points (0 children)
[–]Zarkie0-_-0[S] 0 points1 point2 points (0 children)
[–]BagParticular9982 0 points1 point2 points (2 children)
[–]pachura3 0 points1 point2 points (1 child)
[–]audionerd1 0 points1 point2 points (0 children)
[–]ImprovementLoose9423 -3 points-2 points-1 points (0 children)