How do these Java concepts translate to Python?

Paul McGuire ptmcg at austin.rr.com
Fri Aug 12 01:38:10 EDT 2005


Instance variables are typically defined in __init__(), but they can be
added to an object anywhere. The only exception is when defining the
magic __slots__ class variable to pre-define what the allowed instance
variables can be.

class A:
  pass

a = A()
a.instVar1 = "hoo-ah"
a.instVar2 = "another"

Try that in C++ or Java!

-- Paul




More information about the Python-list mailing list