Paul's Python CoursePPC

self

Not met yet

self is the object a method was called on. red.hire("Yahya") runs hire with self as red, so you never pass it yourself, and every attribute the object keeps is reached through it. Called on the class instead, Bike.hire("Ann"), there is no object to pass, and "Ann" lands in self.

Try it

main.py

Output

Press Run and what your program prints shows up here.

Easy to get wrong

  • Thinks the caller must pass self, the object, as an argument when calling a method on it.
  • Thinks self means the class rather than the one object the method was called on.

Where it comes up