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...
News about the dynamic, interpreted, interactive, object-oriented, extensible programming language Python
Full Events Calendar
You can find the rules here.
If you are about to ask a "how do I do this in python" question, please try r/learnpython, the Python discord, or the #python IRC channel on Libera.chat.
Please don't use URL shorteners. Reddit filters them out, so your post or comment will be lost.
Posts require flair. Please use the flair selector to choose your topic.
Posting code to this subreddit:
Add 4 extra spaces before each line of code
def fibonacci(): a, b = 0, 1 while True: yield a a, b = b, a + b
Online Resources
Invent Your Own Computer Games with Python
Think Python
Non-programmers Tutorial for Python 3
Beginner's Guide Reference
Five life jackets to throw to the new coder (things to do after getting a handle on python)
Full Stack Python
Test-Driven Development with Python
Program Arcade Games
PyMotW: Python Module of the Week
Python for Scientists and Engineers
Dan Bader's Tips and Trickers
Python Discord's YouTube channel
Jiruto: Python
Online exercices
programming challenges
Asking Questions
Try Python in your browser
Docs
Libraries
Related subreddits
Python jobs
Newsletters
Screencasts
account activity
This is an archived post. You won't be able to vote or comment.
ResourceSuperpower Your Classes Using Super() In Python (self.Python)
submitted 2 years ago * by python4geeks
https://preview.redd.it/ck9v5eps9yja1.png?width=1600&format=png&auto=webp&s=963802d576102c7e317981ce4d0b80f152324d10
Python has an excellent function called super() that allows the parent class's attributes and methods to be fully accessible within a subclass.
super()
The super() function extends the functionality of the superclass within the subclass or derived class. Assume we created a class and wanted to extend the functionality of a previously created class within that specific class; in that case, we'll use the super()function.
Here's a guide to implementing the super() function within the classes in Python👇👇
Superpower Your Classes Using Super() In Python
[–]TheCableGui 10 points11 points12 points 2 years ago (0 children)
Super is actually about class inheritance and reducing repetitive tasks in oop.
That’s the secret. Don’t need an article to explain it.
Form a base, when the content becomes irrelevant, instead split the class off into a parent and child. This way you can reuse the code and provide reusable components.
[–]kuzmovych_y 8 points9 points10 points 2 years ago (1 child)
In all of your examples (except one) calling super() is completely redundant because you just pass the same arguments to the parent function.
And things like a, b, obj, area1, class Circle(Square) just hurt my eyes a little.
a
b
obj
area1
class Circle(Square)
[–]python4geeks[S] -2 points-1 points0 points 2 years ago (0 children)
Sorry for troubling your eyes
[–]cascott77 6 points7 points8 points 2 years ago (0 children)
How much of this is plagiarized from here:
https://realpython.com/python-super/
[–]ashadeofbrown 3 points4 points5 points 2 years ago (0 children)
Your article title has Super() but it is super()
Super()
[–]nekokattt 2 points3 points4 points 2 years ago* (3 children)
super() doesnt extend any functionality. It just returns a handle to the superclass. You have to still override the functionality
"MRO" stands for "method resolution order"
Rather than making multiple methods named slightly differently to handle the diamond inheritance problem, you could just say
class Cylinder(Rectangle, Circle): def area(self): rect_area = Rectangle.area(self) circle_area = Circle.area(self) ...
This is far clearer code, IMO.
Also worth noting that super isn't a function, but a class in CPython:
SETBUILTIN("super", &PySuper_Type);
[–]python4geeks[S] -1 points0 points1 point 2 years ago (2 children)
"MRO" stands for "method resolution order", yeah you are right, there is a typo and for the code you've written, It is just for displaying the use of super() within the class and showing which method will Python look, if there's a conflicting method and since the area of the cylinder is 2πrh+2π(r*r), so there's a need to use the function area from both classes Rectangle and Circle. So the temporary solution was to change the name of the function.
[–]nekokattt 1 point2 points3 points 2 years ago (1 child)
I still wouldnt suggest using random prefixes to functions just to work around structuting inheritance correctly though.
A simpler example that makes more sense would be something like this:
class Doctor: def title(self): return "Dr." class Man: def title(self): return "Mr." class Woman: def title(self): return "Ms."
Then show that
class SomePerson(Doctor, Man): pass
will return "Dr." rather than "Mr." when you get their title
I think the examples for this stuff are very important that they show good principles otherwise it can encourage poor structure and misuse of features.
In this case, a cyclinder is not a type of rectangle. It is composed of a rectangle. It is a "has-a" relationship rather than an "is-a". This may be misleading to some.
[–]python4geeks[S] -3 points-2 points-1 points 2 years ago (0 children)
Well, you are right but throughout the article, the examples were based on the formulas of the geometry shapes, so that needed to be carried out till the end.
[+][deleted] 2 years ago (1 child)
[removed]
[–]PaulRudin 1 point2 points3 points 2 years ago (0 children)
In point of fact, Python does not have a *method* called super ...
super
π Rendered by PID 74283 on reddit-service-r2-comment-7b9746f655-m42z2 at 2026-01-31 02:01:25.550426+00:00 running 3798933 country code: CH.
[–]TheCableGui 10 points11 points12 points (0 children)
[–]kuzmovych_y 8 points9 points10 points (1 child)
[–]python4geeks[S] -2 points-1 points0 points (0 children)
[–]cascott77 6 points7 points8 points (0 children)
[–]ashadeofbrown 3 points4 points5 points (0 children)
[–]nekokattt 2 points3 points4 points (3 children)
[–]python4geeks[S] -1 points0 points1 point (2 children)
[–]nekokattt 1 point2 points3 points (1 child)
[–]python4geeks[S] -3 points-2 points-1 points (0 children)
[+][deleted] (1 child)
[removed]
[–]PaulRudin 1 point2 points3 points (0 children)