Hacker News new | ask | show | jobs
by rdtsc 5031 days ago
> It needs to be assigned to "1" explicitly in __init__ as far as I understand.

I don't think so. You do have to assign anything to it if you want to use it as a 'static' (actually 'class' attribute). You can access bar from Foo, as in Foo.bar or from an instance of Foo as in foo=Foo(); foo.bar.

What probably is confusing to you is if you assign a value bar in an instance then that gets assigned to the instance not the class. That is if you do foo.bar=100 then now foo instance has an object attribute called bar=100 that overrides Foo.bar=1. But Foo.bar still stays at 1.

2 comments

You're right, I was mixing something up. You need mutable data structures to show the behaviour I mean, see my other comment in this tree.
EDIT: You do have to assign = You don't have to assign