1 Replies - 624 Views - Last Post: 02 April 2014 - 03:02 PM Rate Topic: -----

#1 MaverocK   User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 60
  • Joined: 21-February 14

difference between class variable and class attribute

Posted 02 April 2014 - 01:54 PM

Would you please explain the difference between class variable and class attribute?

According to this web-page, class attributes are variables owned by the class itself.

For example:

class MP3FileInfo(FileInfo):
    "store ID3v1.0 MP3 tags"
    tagDataMap = {"title"   : (  3,  33, stripnulls),
                  "artist"  : ( 33,  63, stripnulls),
                  "album"   : ( 63,  93, stripnulls),
                  "year"    : ( 93,  97, stripnulls),
                  "comment" : ( 97, 126, stripnulls),
                  "genre"   : (127, 128, ord)}


The web page says tagDataMap is a class attribute. But according to Tutorialspoint.com, "class variable is a variable that is shared by all instances of a class. Class variables are defined within a class but outside any of the class's methods."

So what Tutorialspoint.com calls class variable and what diveintopython.net calls class attribute are the same thing? I believe there are differences between these two terms and I would like to learn.

Thank you!

Is This A Good Question/Topic? 0
  • +

Replies To: difference between class variable and class attribute

#2 andrewsw   User is online

  • never lube your breaks
  • member icon

Reputation: 6829
  • View blog
  • Posts: 28,311
  • Joined: 12-December 12

Re: difference between class variable and class attribute

Posted 02 April 2014 - 03:02 PM

From the tutorialspoint link:

Quote

Class: A user-defined prototype for an object that defines a set of attributes that characterize any object of the class. The attributes are data members (class variables and instance variables) and methods, accessed via dot notation.

Attributes is the more general term.

Where Python uses the term attributes other languages use the term members. OOP terminology isn't used very consistently I'm afraid.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1