Python doesn’t have a concept of public and private members of an object. By polite agreement, data that is intended to be private is prefaced with an underscore, but all object attributes are publicly accessible.
The same variable for every instance of the class? You can do that, but it tends to lead to very counterintuitive results and is considered an antipattern.
Yeah the error happens because “global” isn’t doing what you think it does.
The keyword actually tells Python to “look” for the global variable, not creating it. Meaning without using global amount in your deposit(), Python creates amount as local varibale there. Which then throws an error because Python can’t += a variable that’s not yet initialized.