class foo(object)def bar(self)print("bar!"def spam(self)bar(selfincorrect'bargenerates nameerror self bar(this works foo bar(selfthis also works the lack of scoping in classes is one area where python differs from +or java if you have used those languagesthe self parameter in python is the same as the this pointer the explicit use of self is required because python does not provide means to explicitly declare variables (that isa declaration such as int or float in cwithout thisthere is no way to know whether an assignment to variable in method is supposed to be local variable or if it' supposed to be saved as an instance attribute the explicit use of self fixes this--all values stored on self are part of the instance and all other assignments are just local variables inheritance inheritance is mechanism for creating new class that specializes or modifies the behavior of an existing class the original class is called base class or superclass the new class is called derived class or subclass when class is created via inheritanceit "inheritsthe attributes defined by its base classes howevera derived class may redefine any of these attributes and add new attributes of its own inheritance is specified with comma-separated list of base-class names in the class statement if there is no logical base classa class inherits from objectas has been shown in prior examples object is class which is the root of all python objects and which provides the default implementation of some common methods such as _str_ ()which creates string for use in printing inheritance is often used to redefine the behavior of existing methods as an examplehere' specialized version of account that redefines the inquiry(method to periodically overstate the current balance with the hope that someone not paying close attention will overdraw his account and incur big penalty when making payment on their subprime mortgageimport random class evilaccount(account)def inquiry(self)if random randint( , = return self balance elsereturn self balance notepatent pending idea evilaccount("george" deposit( calls account deposit( , available inquiry(calls evilaccount inquiry(cin this exampleinstances of evilaccount are identical to instances of account except for the redefined inquiry(method inheritance is implemented with only slight enhancement of the dot operator specificallyif the search for an attribute doesn' find match in the instance or the instance' classthe search moves on to the base class this process continues until there are no more base classes to search in the previous examplethis explains why deposit(calls the implementation of deposit(defined in the account class lib fl ff