1

Possible Duplicate:
Python: Difference between class and instance attributes

class a:
    m = 1
    def __init__(self):
        self.n = 2

According to the book I am reading, m is called class attributes and n is called data attributes, but what's the difference between them?

It seems that the operations of them is nearly same. The only difference I can tell is one is in the function __init__ and another isn't.

Community
  • 1
  • 1
Searene
  • 25,920
  • 39
  • 129
  • 186
  • If the difference between a class attribute and an instance attribute isn't immediately obvious, then you need to go back and read the explanation of the difference between a class and an instance again. A class attribute is one that is part of the class. An instance attribute is one that is part of the instance. – Karl Knechtel Nov 12 '11 at 15:25
  • For me what's rather surprising is why does the book call instance attributes, usually simply called attributes, "data" attributes? It seems like it's mixing two different things. I was under the impression that "data" meant to emphasize values meant to be contansts (at a given version) from a design perspective. – n611x007 Oct 05 '15 at 14:26

1 Answers1

-1

This is essentially a duplicate of this question which has an example of the difference.

Python: Difference between class and instance attributes

Community
  • 1
  • 1
jjh
  • 1,410
  • 2
  • 13
  • 13