Can a method parameter have the same name as an instance variable?



Can a parameter to a method have the same variable name as an instance variable for a class?


Although the parameter and instance variable may appear to share the same name, the instance variable is referenced using self. so they are actually two different variables even though they may appear similar. The following code example shows a method parameter name and an instance variable While they may appear to be similar, they are actually two different variables.

class Vars:

    def __init__(self): = "Instance Var"

    def show(self, name):
        print("name = " + name)
        print(" = " +

test = Vars()"this is a parameter")

# name = this is a parameter
# = Instance Var