I saw this thread a few days ago, and I understand(after reading the answers) why the OP was getting the behavior in question, but I do not understand what is happening with the dot operator being used on the "add" function: print add().a. a is an element of class test, and add creates an instance of test, but how is a being accessed right on the function?
Add a comment
|
2 Answers
In that post, the function add() returns a test object. That object has an attribute a, so it can be accessed using the . operator.
In other words, add().a accesses the attribute a of the result of the function call to add, not of the function object itself (that would be add.a).
1 Comment
Tim Pietzcker
@JakeSellers: I'm not sure I understand.
.a is applied to whatever add() returns, regardless of how many other things it does.