python - Python 中的一切都像 Ruby 一样是对象吗?

标签 python ruby object language-comparisons

我在另一个 Stack Overflow 问题上读到 Python 就像 Ruby,因为它与“一切都是对象”有关,而 Python 中的一切都是对象,就像 Ruby 一样。

这是真的吗?像 Ruby 一样,Python 中的一切都是对象吗?

两者在这方面有何不同,还是真的相同?例如,你能拿一个数字做我见过的 Ruby 的东西吗:

y = 5.plus 6

这可以在 Python 中以同样的方式完成吗?

最佳答案

DiveIntoPython - Everything Is an Object

Everything in Python is an object, and almost everything has attributes and methods. All functions have a built-in attribute __doc__, which returns the doc string defined in the function's source code. The sys module is an object which has (among other things) an attribute called path. And so forth.

Still, this begs the question. What is an object? Different programming languages define “object” in different ways. In some, it means that all objects must have attributes and methods; in others, it means that all objects are subclassable. In Python, the definition is looser; some objects have neither attributes nor methods (more on this in Chapter 3), and not all objects are subclassable (more on this in Chapter 5). But everything is an object in the sense that it can be assigned to a variable or passed as an argument to a function (more in this in Chapter 4).

Ruby Docs - To Ruby From Python

As with Python, in Ruby,... Everything is an object

你可以从 Ruby 自己的网站获得它:在 Python 中,一切都是对象。

关于python - Python 中的一切都像 Ruby 一样是对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/865911/

相关文章:

python - Kedro:如何从命令行传递 "list"参数?

python - 异常签名

javascript - 如何更改 javascript 原型(prototype)对象的属性

javascript - JavaScript 中的对象和对象文字

python - 在 2 个 python 列表中查找具有共同属性的对象的有效方法

python - IO错误: unable to receive websocket message

javascript - ajax请求后脚本不再工作

ruby - 如何将 Ruby 数组拆分成一定数量的较小数组?

ruby - 在 Ruby 中对字符串和数字进行排序

c# - Xamarin C# - IMKAnnotation 不包含 'x' 的定义