| |||||||||||
Everything is an object Posted by admin (Graham Ellis), 14 January 2005 In Python, everything's an object. Might seem odd at first, but the more you get to know it the more clear and logical it is. Even methods are named objects!Have a look at this example piece of code: Code:
And when it runs, you get: Code:
Why is everything doubled when you use the += operator? Objects explain in all. In the first case, a new object is created each time something is added onto the end of the previous list. But in the second case, something is added onto the end of the existing list in the loop; since c2cat and c2dog are just two different names for the same object, that something added is added twice. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |