How to explain an attribute in Python to a novice

后端 未结 3 958
甜味超标
甜味超标 2021-01-27 04:19

Can anyone explain in simple words what an attribute in Python language is?

For instance what can I say about

list.append(x)

which adds

3条回答
  •  不要未来只要你来
    2021-01-27 04:43

    See the python documentation : Especially 9.3.3. Instance Objects: There are two kinds of valid attribute names, data attributes and methods. You'll find there examples, too. So, why are methods also called attributes? For some methods the term "attribute" fits better, than for others. Example:

    car.color()
    

    This method may return the color of the car.

    Take it just as a matter of definition and generalization that the word after the dot is called an attribute of the object before the dot.

提交回复
热议问题