Two
class has an instance method name()
. Thus, Two.name
refers to this method, and the following code works fine:
Polly = Two() Two.name(Polly)
However, in __init__()
you override name
by setting it to a string, so anytime you create a new instance of Two
, the name
attribute will refer to the string instead of the function. Here's why the following:
Polly = Two() # Polly.name is now the string 'Polly' Polly.name() # this is equivalent to 'Polly'()
Just make sure you use separate variable names for your methods and your instance variables.
source share