Python是否已改为面向对象? [英] Has Python changed to more object oriented?

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

问题描述

我记得有一次,他说Python比Ruby少面向对象,因为在Ruby中,一切都是对象. Python也有所改变吗?最新的Python是否比以前的版本更面向对象?

I remember that at one point, it was said that Python is less object oriented than Ruby, since in Ruby, everything is an object. Has this changed for Python as well? Is the latest Python more object oriented than the previous version?

推荐答案

Jian Lin —答案是是",与Matz决定创建Ruby相比,Python更加面向对象,并且两种语言现在都具有所有功能"是一个对象".早在Python年轻时,诸如字符串和数字之类的类型"就缺少方法,而对象"是使用"class"语句构建的(或者通过在C扩展模块中故意构建一个类)构建的,虽然效率较低,但确实支持方法和继承.在1990年代初期,当一台快速386是一台非常不错的机器时,这种折衷是有道理的.但是类型和类在Python 2.2(2001年发布)中是统一的,字符串具有方法,并且在最新的Python版本中,用户甚至可以从中继承子类.

Jian Lin — the answer is "Yes", Python is more object-oriented than when Matz decided he wanted to create Ruby, and both languages now feature "everything is an object". Back when Python was younger, "types" like strings and numbers lacked methods, whereas "objects" were built with the "class" statement (or by deliberately building a class in a C extension module) and were a bit less efficient but did support methods and inheritance. For the very early 1990s, when a fast 386 was a pretty nice machine, this compromise made sense. But types and classes were unified in Python 2.2 (released in 2001), and strings got methods and, in more recent Python versions, users can even subclass from them.

因此:Python一次肯定不是面向对象的.但是据我所知,这些古老的障碍中的每一个现在都消失了.

So: Python was certainly less object oriented at one time; but, so far as I know, every one of those old barriers is now gone.

这是发生统一的指南:

http://www.python.org/download/releases/2.2/descrintro /

说明:也许我可以更简单地说:在Python中,所有内容始终都是对象.但是某些基本类型的对象(整数,字符串)曾经由不同的规则"播放,这些对象阻止了OO编程方法(例如继承)与它们一起使用.现在已解决. len()方法(在此处的另一个响应中描述)可能是我希望Guido在升级到Python 3.0时所做的唯一更改.但是至少他给了我字典理解能力,所以我不会大声抱怨. :-)

Clarification: perhaps I can put it even more simply: in Python, everything has always been an object; but some basic kinds of object (ints, strings) once played by "different rules" that prevent OO programming methods (like inheritance) from being used with them. That has now been fixed. The len() method, described in another response here, is probably the only thing left that I wish Guido had changed in the upgrade to Python 3.0. But at least he gave me dictionary comprehensions, so I won't complain too loudly. :-)

这篇关于Python是否已改为面向对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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