Methods and self

A method is a function defined inside a class. When you call acct.deposit(500), Python passes acct as the first argument, so it really runs Account.deposit(acct, 500). That first parameter is named self by convention.

Methods read and change the object through self. Forget self. and you change a local variable instead.

Forget self in the def line and the call fails with a confusing message: deposit() takes 1 positional argument but 2 were given. The "extra" argument is the object itself. Interviewers like this one in debugging rounds.

Run it, then add a withdraw method that refuses to go below zero.