Superclass and Self in Object Oriented Programming - Python

Hello,

I am learning about OOP in python and I have a question regarding the syntax of superclass methods. When defining a method in a subclass which will then use super() to use the functionality of the superclass + some modification, why is the “self” omitted if it is put in when defining in the superclass.

class Employee():
  new_id = 1
  def __init__(self):
    self.id = Employee.new_id
    Employee.new_id += 1

  def say_id(self):
    print("My id is {}.".format(self.id))

class Admin(Employee):
  def say_id(self):
    super().say_id()
    print("I am an admin.")
    # why do I omit "self" in this definition when using super()

Thank you so much <3

self is the same instance object in both contexts.

1 Like

Ah, I see. That makes a lot of sense, I got tunnel-visioned and forgot to follow the code from the start tbh.
Thank you so much for your answer. :smiley:

1 Like