Misconception: Students get confused with object-oriented programming in Python because function declarations explicitly take self as an argument, but function calls don’t use self as argument.

  • In the Python example below, notice how the method setSides has two formal parameters, but when we call it in main(), we only pass one argument.
      class Die: def setSides(self, sides):
        self.numSides = sides
      def main():
        die1 = Die() die1.setSides(3)
  • If students are learning Object-Oriented Programming while transitioning between two languages, like Python and Java, this can be even more confusing.
    • In Java, self is an implicit argument when a method is defined. In Python, self is an explicit argument. In both Python and Java, self isn’t a required argument when the method/function is called.
      • As such, students struggle with reasoning about object oriented function declarations between Python and Java.
    • If students are moving from Python to Java, point them to Ken Lambert’s Python to Java resource for additional help.

More about this tip

External Source
Interview with Dave Musicant.