如何向新手解释Python中的属性 [英] How to explain an attribute in Python to a novice

查看:36
本文介绍了如何向新手解释Python中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以用简单的单词解释Python语言中的属性是什么吗?

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

例如,我能说些什么

list.append(x)

使用直观,简单的日常生活示例将对象添加到列表的末尾?我发现属性描述了一个对象的属性,而我的头发的属性例如是棕色且短.

which adds an object at the end of the list, using an intuitive, simple everyday life example? I found that attributes describe a property of an object, and property of my hair for instance is that they are brown and short.

很好,但是如果是这样, append 属性描述了 list 的什么属性?可以在 list 的末尾添加一些内容吗?我会说这是对 list 的操作,而不是其属性.

Very well, but if so, what property of list does the append attribute describe? That one may add something at the end of the list? I would say that this is an operation on the list rather than its property.

能否请您为我澄清一下?

Could you clarify this for me, please?

推荐答案

请参见 python文档:特别是9.3.3.实例对象:有两种有效的属性名称:数据属性和方法.您还会在其中找到示例.那么,为什么方法也称为属性?对于某些方法,术语属性"比其他方法更合适.示例:

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.

这篇关于如何向新手解释Python中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆