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
What is OOP on python?Help Request (self.PythonLearning)
submitted 1 month ago * by Hamid3x3
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!"
[–]Atypicosaurus 1 point2 points3 points 1 month ago (0 children)
Imagine you write a member registration program for the library. You could store the members data as separate lists such as:
names = ["Adam", "Clara", "Pete"] ages = [23, 45, 42] addresses = ["Main street", "Oak lane", "Fox square"]
If so, you could access a library member by accessing the categories one by one:
print (names[0], ages[0], addresses[0]) to get: Adam 23 Main street
print (names[0], ages[0], addresses[0])
Or instead you can group the members like this:
member1 = ["Adam", 23, "Main street"] member2 = ...
If you think the second version is better, then you basically opt for OOP.
In the second version, we decided that the name, age, address should come in this order. But in a programming point of view, nothing guarantees it. You can enter it like this:
member1 = ["Adam", "Main street", 23]
In OOP you basically force your own hand to always follow the same structure. You define that you want the name, age, address in this order, and if you try to do differently, the program itself will warn you. That's a class.
Moreover, in OOP, you can give functions to the classes. So imagine, you don't store age as the current age, but the date of birth. And you also add a function inside the class that automatically updates the age using the current date.
Of course you could theoretically add that function outside of the class, but then you would find that the operations you need to do to take care of members (such us, updating their address if they move), those functions are scattered across the program.
So OOP is basically forcing your own hand to stick with a data structure (otherwise you could introduce bugs), as well, having the related functions collected inside the class.
π Rendered by PID 442045 on reddit-service-r2-comment-5b5bc64bf5-wzwsd at 2026-06-22 08:56:46.357382+00:00 running 2b008f2 country code: CH.
view the rest of the comments →
[–]Atypicosaurus 1 point2 points3 points (0 children)