2006-01-31

Python | Declaring 'Class' and 'Instance' variables

How should one declare 'class' and 'instance' variables in Python ?

Well, in Python, assignment is declaration. You just need to assign the variables in the appropriate place.

If you intend to declare a 'class' variable, that is, a variable stored for the class and accessible through each instance, you code 'name = value' for that variable inside the class statement.

If you intend to declare a separate attribute for each instance, you code 'name = value' for that variable it in the '__init__' method.

0 Comments:

Post a Comment

<< Home