On 7/16/19 2:33 PM, Steven D'Aprano wrote:
> x = Parrot()
>
> Now x is a reference to a Parrot instance. y remains a reference to the
> list.
>
> x.colour is a reference to the string "blue" (by default).
>
> x.speak is a reference to the "speak" method of Parrot objects.
>
>
>
> Does this help?
>
>
>
Let's add one more little cute one for good measure:
>>> def foo():
... print("This function does Foo")
...
>>> foo()
This function does Foo
>>> # we created a function object, and foo is a reference to it
...
>>> x = foo
>>> # x should be a reference to the same object
...
>>> x()
This function does Foo
>>> x is foo
True
>>> def foo():
... print("This function no longer Foos")
...
>>> # we created a new function object, and foo is now a reference to it
...
>>> foo()
This function no longer Foos
>>> x()
This function does Foo
>>> # x is still a reference to the original function object
...
>>> x is foo
False
>>>
_______________________________________________
Tutor maillist - [email protected]
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor