什么不是Python中的对象? [英] What is not objects in Python?

查看:122
本文介绍了什么不是Python中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听过一些关于Python的批评,它不完全是对象 -

导向。


什么不是Python中的对象?


为什么不将len实现为str.len和list.len方法而不是

a len(list)函数?

I have heard some criticism about Python, that it is not fully object-
oriented.

What is not an object in Python?

Why isn''t len implemented as a str.len and list.len method instead of
a len(list) function?

推荐答案

process写道:
process wrote:

什么不是Python中的对象?
What is not an object in Python?



所有不属于Python语法的东西都是一个对象,包括

所有字符串和数字类型,类,元类,功能,型号,

代码等。从技术上来说,不可能有像

这样的东西,这不是一个对象。

Everything that is not part of Python''s syntax is an object, including
all string and number types, classes, metaclasses, functions, models,
code and more. It''s technically not possible to have something like e.g.
an int that isn''t an object.


为什么不是'' t len实现为str.len和list.len方法而不是

a len(list)函数?
Why isn''t len implemented as a str.len and list.len method instead of
a len(list) function?



因为可读性比纯度更重要。顺便说一句len(鸡蛋)

只是鸡蛋的语法糖.__ len __()还有一些额外的检查。

Because readability is more important than purity. By the way len(egg)
is just syntactic sugar for egg.__len__() with some extra checks.


On 9月29日,1:29 * am,进程< circularf ... @ gmail.comwrote:
On Sep 29, 1:29*am, process <circularf...@gmail.comwrote:

我听到一些关于Python的批评,认为它并不完全对象 -

导向。


什么不是Python中的对象?


为什么不是len实现为str.len和list.len方法而不是

a len(list)函数?
I have heard some criticism about Python, that it is not fully object-
oriented.

What is not an object in Python?

Why isn''t len implemented as a str.len and list.len method instead of
a len(list) function?



像这样的问题经常被另一个问题回答(修辞)

问题:实际上什么是面向对象?


答案通常是:Python不是Java。

A question like this is often answered by another (rhetorical)
question: "What is Object Oriented actually?"

The answer to that is generally: "Python is not Java."


process写道:
process wrote:

我听过一些关于Python的批评,认为它不是完全对象 -

导向。
I have heard some criticism about Python, that it is not fully object-
oriented.



如果你愿意,可以随意忽略它。

Feel free to ignore it if you wish.


什么不是Python中的对象?
What is not an object in Python?



取决于你所说的''in''。 Python是一种用于定义和操作信息对象的语言。代码'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''代码中仅用于直接访问对象的名称

通常也不是对象本身。

Depends on what you mean by ''in''. Python is a language for defining and
manipulating information objects. Code ''in'' Python is not usually a
maniputed object, though is can be (by eval, exec, and compile, for
instance). Names in code that are only used to directly access objects
typically are also, typically, not objects themselves.


为什么不是len实现为str.len和list.len方法而不是

a len(list)函数?
Why isn''t len implemented as a str.len and list.len method instead of
a len(list) function?



部分历史和部分实用性。 Len实现为.__ len__

;-)。 len函数是一个,__ len__方法很多。如果你想将
传递给函数一个参数,那么传递len更容易传递

operator.attrgetter(''__ len__'')。传递''__len__''(或''len'')将很容易,但是使用len比使用getattr更容易(ob,''__ len__'')。


tjr



Partly history and partly practicality. Len is implemented as .__len__
;-). The len function is one, __len__ methods are many. If you want to
pass an argument to a function, passing len is easier that passing
operator.attrgetter(''__len__''). Passing ''__len__'' (or ''len'') would be
easy, but using len is easier than using getattr(ob,''__len__'').

tjr



这篇关于什么不是Python中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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