self.show() vs super().show()

Since you said, Maham, we can use self if we are not creating a child class constructor, right? Then why did you use super() instead of self here?

class BankAccount:
    def show(self):
        print("Parent show")

class SavingsAccount(BankAccount):
    def show(self):
        super().show()
        print("Child show")

👉 why super().show() instead of self.show()?

because:

  • self.show() → will call the method inside the current class first
    (and if it exists, it’ll call itself again and again → infinite loop 😵)

so if you write this:

def show(self):
    self.show()

boom 💥
RecursionError: maximum recursion depth exceeded


but super().show() → it says:

"call the parent class version of the method"

so this is how we use parent method inside the child class safely without recursion


When to use self.show() vs super().show()?

You want to call...

Use

Method from current class (not overridden)

self.show()

Parent class method (especially if overridden in child)

super().show()


real case analogy:

You’re in a child class and want to use some base logic from parent’s method
but also want to extend it by adding your own lines → use super().method()

Updated on