Class Variable Access and Assignment

Paul Rubin http
Thu Nov 3 07:30:09 EST 2005


Steve Holden <steve at holdenweb.com> writes:
> > class A:
> >   a = 1
> > b = A()
> > b.a += 2
> > print b.a
> > print A.a
> > Which results in
> > 3
> > 1
> >
> I don't suppose you'd care to enlighten us on what you'd regard as the
> superior outcome?

    class A:
      a = []
    b = A()
    b.append(3)
    print b.a
    print a.a

Compare and contrast.



More information about the Python-list mailing list