Bird
Raised Fist0
Pythonprogramming~20 mins

Super function usage in Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Super Function Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of super() in multiple inheritance
What is the output of this Python code using super() in multiple inheritance?
Python
class A:
    def greet(self):
        return "Hello from A"

class B(A):
    def greet(self):
        return super().greet() + " and B"

class C(A):
    def greet(self):
        return super().greet() + " and C"

class D(B, C):
    def greet(self):
        return super().greet() + " and D"

obj = D()
print(obj.greet())
A"Hello from A and B and C and D"
B"Hello from A and C and D"
C"Hello from A and B and D"
D"Hello from A and C and B and D"
Attempts:
2 left
💡 Hint
Remember that super() follows the method resolution order (MRO) in multiple inheritance.
Predict Output
intermediate
1:30remaining
Using super() with arguments
What will be printed when running this code that uses super() with arguments?
Python
class Base:
    def __init__(self, x):
        self.x = x

class Child(Base):
    def __init__(self, x, y):
        super(Child, self).__init__(x)
        self.y = y

obj = Child(5, 10)
print(obj.x, obj.y)
A10 5
B5 10
CTypeError
DAttributeError
Attempts:
2 left
💡 Hint
Check how super() is called with explicit arguments and how the base class constructor is called.
Predict Output
advanced
1:00remaining
Effect of missing super() call in override
What is the output of this code where a subclass overrides a method but does NOT call super()?
Python
class Parent:
    def action(self):
        return "Parent action"

class Child(Parent):
    def action(self):
        return "Child action"

obj = Child()
print(obj.action())
ATypeError
B"Parent action"
C"Child action"
DAttributeError
Attempts:
2 left
💡 Hint
If a method is overridden without calling super(), the base method is not executed.
Predict Output
advanced
2:00remaining
super() in diamond inheritance pattern
What will this code print when using super() in a diamond inheritance pattern?
Python
class Top:
    def process(self):
        return "Top"

class Left(Top):
    def process(self):
        return super().process() + "->Left"

class Right(Top):
    def process(self):
        return super().process() + "->Right"

class Bottom(Left, Right):
    def process(self):
        return super().process() + "->Bottom"

obj = Bottom()
print(obj.process())
A"Top->Right->Left->Bottom"
B"Top->Left->Bottom"
C"Top->Right->Bottom"
D"Top->Left->Right->Bottom"
Attempts:
2 left
💡 Hint
Check the method resolution order (MRO) for Bottom and how super() calls chain.
🧠 Conceptual
expert
1:30remaining
Why use super() instead of direct parent class call?
Which is the best reason to use super() instead of directly calling a parent class method in Python?
Asuper() automatically follows the method resolution order, supporting multiple inheritance correctly.
Bsuper() is faster than direct parent class calls.
Csuper() allows calling private methods of the parent class.
Dsuper() can only be used in single inheritance, making code simpler.
Attempts:
2 left
💡 Hint
Think about how Python handles multiple inheritance and method calls.

Practice

(1/5)
1. What is the main purpose of using super() in a child class?
easy
A. To call a method from the parent class
B. To create a new instance of the child class
C. To delete the parent class
D. To override the child class method completely

Solution

  1. Step 1: Understand what super() does

    super() is used to access methods from the parent class inside a child class.
  2. Step 2: Identify the correct purpose

    Calling a parent class method helps reuse code and extend functionality.
  3. Final Answer:

    To call a method from the parent class -> Option A
  4. Quick Check:

    super() calls parent method = A [OK]
Hint: Remember: super() means 'call parent method' [OK]
Common Mistakes:
  • Thinking super() creates new objects
  • Believing super() deletes classes
  • Assuming super() overrides child methods fully
2. Which of the following is the correct syntax to call a parent class method greet inside a child class method using super()?
easy
A. super().greet()
B. super->greet()
C. super[greet]()
D. super.greet()

Solution

  1. Step 1: Recall the syntax of super()

    The correct way to call a parent method is using super() followed by dot and method name.
  2. Step 2: Match the correct option

    Only super().greet() uses the right parentheses and dot notation.
  3. Final Answer:

    super().greet() -> Option A
  4. Quick Check:

    Use parentheses with super() = D [OK]
Hint: super() always needs parentheses before method call [OK]
Common Mistakes:
  • Omitting parentheses after super
  • Using square brackets instead of parentheses
  • Using arrow notation which is invalid in Python
3. What will be the output of this code?
class Parent:
    def greet(self):
        return "Hello from Parent"

class Child(Parent):
    def greet(self):
        return super().greet() + " and Child"

c = Child()
print(c.greet())
medium
A. Hello from Parent
B. Hello from Child
C. Hello from Parent and Child
D. Error: super() not used correctly

Solution

  1. Step 1: Understand method calls in Child.greet()

    Child's greet calls super().greet() which runs Parent's greet returning Hello from Parent.
  2. Step 2: Combine returned strings

    Child's greet adds and Child to the parent's string, so final output is Hello from Parent and Child.
  3. Final Answer:

    Hello from Parent and Child -> Option C
  4. Quick Check:

    super() calls parent method + extra text = A [OK]
Hint: super() returns parent result; child can add more [OK]
Common Mistakes:
  • Expecting only parent's message without child addition
  • Thinking super() causes error here
  • Ignoring the string concatenation
4. Find the error in this code using super():
class Base:
    def show(self):
        print("Base show")

class Derived(Base):
    def show(self):
        super.show()
        print("Derived show")

d = Derived()
d.show()
medium
A. Derived class should not override show()
B. Base class method show() is missing
C. print statements are incorrect
D. super.show() should be super().show()

Solution

  1. Step 1: Identify how super() is called

    The code uses super.show() which is invalid syntax; super must be called as a function.
  2. Step 2: Correct the syntax

    It should be super().show() to properly call the parent method.
  3. Final Answer:

    super.show() should be super().show() -> Option D
  4. Quick Check:

    super() needs parentheses before method = C [OK]
Hint: Always use super() with parentheses before method call [OK]
Common Mistakes:
  • Calling super without parentheses
  • Thinking parent method is missing
  • Believing overriding is not allowed
5. You want to extend a parent class __init__ method to add a new attribute in the child class. Which code correctly uses super() to do this?
class Animal:
    def __init__(self, name):
        self.name = name

class Dog(Animal):
    def __init__(self, name, breed):
        ???
        self.breed = breed
Choose the correct replacement for ???.
hard
A. super(Dog, self).__init__(breed)
B. super().__init__(name)
C. Animal.__init__(self, breed)
D. super().__init__(breed)

Solution

  1. Step 1: Understand parent __init__ parameters

    Animal's __init__ takes name, so we must pass name to it.
  2. Step 2: Use super() correctly in child __init__

    Calling super().__init__(name) runs Animal's __init__ properly, then child adds breed.
  3. Final Answer:

    super().__init__(name) -> Option B
  4. Quick Check:

    super() calls parent with correct args = B [OK]
Hint: Pass parent's expected args to super().__init__() [OK]
Common Mistakes:
  • Passing wrong argument to super()
  • Calling parent __init__ without self
  • Using old super() syntax incorrectly