What is attribute stands for in Python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • psbasha
    Contributor
    • Feb 2007
    • 440

    #1

    What is attribute stands for in Python?

    I saw some of the Books ,they are referring to attributes.Corr ect me if my understanding is correct about the attributes.

    In classes we have data variables and methods.So clubbing together they are called as attributes.

    Thanks
    PSB
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Originally posted by psbasha
    I saw some of the Books ,they are referring to attributes.Corr ect me if my understanding is correct about the attributes.

    In classes we have data variables and methods.So clubbing together they are called as attributes.

    Thanks
    PSB
    An 'attribute' is a property or value associated with an object. A method performs an operation of some sort on an object. Both are accessed with the dot operator.

    Comment

    • psbasha
      Contributor
      • Feb 2007
      • 440

      #3
      Thanks for the reply.

      So attribute is a member variable of a class.

      -PSB

      Comment

      • bartonc
        Recognized Expert Expert
        • Sep 2006
        • 6478

        #4
        Originally posted by psbasha
        Thanks for the reply.

        So attribute is a member variable of a class.

        -PSB
        Sometimes called "members", as a group, methods, class variables and instance variables are all attributes of objects:

        >>> class aClass:
        ... a = 1
        ... def aFunc():
        ... pass
        ...
        >>> inst = aClass() # create and instance
        # Check to see if the instance has attributes
        >>> hasattr(inst, 'a')
        True
        >>> hasattr(inst, 'aFunc')
        True
        >>>

        Comment

        • bvdet
          Recognized Expert Specialist
          • Oct 2006
          • 2851

          #5
          Originally posted by bartonc
          Sometimes called "members", as a group, methods, class variables and instance variables are all attributes of objects:

          >>> class aClass:
          ... a = 1
          ... def aFunc():
          ... pass
          ...
          >>> inst = aClass() # create and instance
          # Check to see if the instance has attributes
          >>> hasattr(inst, 'a')
          True
          >>> hasattr(inst, 'aFunc')
          True
          >>>
          I agree that methods are commonly referred to as attributes (data and method attributes). However, by definition they are different.

          Comment

          • psbasha
            Contributor
            • Feb 2007
            • 440

            #6
            So Class attributes means -> Data Memebers ( Variables and Methods in a class).Similar to C++ terminology or OOPs

            Comment

            • bartonc
              Recognized Expert Expert
              • Sep 2006
              • 6478

              #7
              Originally posted by psbasha
              So Class attributes means -> Data Memebers ( Variables and Methods in a class).Similar to C++ terminology or OOPs
              Object Oriented terminology predates C++. I borrow my use of the terms from books on OO Analysis and OO Design.

              Comment

              • psbasha
                Contributor
                • Feb 2007
                • 440

                #8
                Hi,

                Could you please suggest me the Books on OOAD.

                Thanks
                -PSB

                Comment

                • bartonc
                  Recognized Expert Expert
                  • Sep 2006
                  • 6478

                  #9
                  Originally posted by psbasha
                  Hi,

                  Could you please suggest me the Books on OOAD.

                  Thanks
                  -PSB
                  Here is a PDF that looks good. Here is a web site with that name. Here you will find a cheap copy of a book that was very useful to me. Just google "Object Oriented Analysis" for more resources.

                  Comment

                  Working...