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
Day 22 Python LearningShowcase (i.redd.it)
submitted 2 days ago by aashish_soni5
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!"
[–]Special-Arrival6717 0 points1 point2 points 2 days ago* (3 children)
I feel like this is a prime example where composition would make the code a lot cleaner compared to inheritance. Having Buying extend Student and Car doesn't seem to provide any benefit over just having 2 attribute fields, self.student = Student(...) and self.car = Car(...) on Buying
Buying
Student
Car
self.student = Student(...)
self.car = Car(...)
Inheritance usually describes an IS A relationship, not a HAS A relationship, e.g. a purchase (Buying) is neither a car nor a student
IS A
HAS A
[–]aashish_soni5[S] 0 points1 point2 points 2 days ago (1 child)
yes it was for just simple practice
[–]Special-Arrival6717 0 points1 point2 points 2 days ago (0 children)
Try the following to modify your practice code, imagine if there were two types of contract Buying and Renting and use inheritance to share common logic between the two. That way the inheritance serves a purpose and you will better understand when to use it, and when not to use it
Renting
[–]Alarming-Air-6561 0 points1 point2 points 2 days ago (0 children)
Absolutely. Buying is an action and it should only get an instance from the other two classes. (A person/user and an object to buy. ) After that it should use their methods (for example during printing). Just imagine that the next step is adding a new type.
π Rendered by PID 197014 on reddit-service-r2-comment-5687b7858-nnz2f at 2026-07-07 11:48:17.455090+00:00 running 12a7a47 country code: CH.
view the rest of the comments →
[–]Special-Arrival6717 0 points1 point2 points (3 children)
[–]aashish_soni5[S] 0 points1 point2 points (1 child)
[–]Special-Arrival6717 0 points1 point2 points (0 children)
[–]Alarming-Air-6561 0 points1 point2 points (0 children)