在 x = 1
, 都是 x
和 1
对象?因为 print(1)
和 x = 1; print(x)
将导致相同的输出。
甚至 print
的语法功能是:
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
最佳答案
Python 中的名称不是对象。在表达式中使用名称会自动计算名称所引用的对象。不可能以任何方式与名称本身交互,例如传递它或调用它的方法。
>>> x = 1
>>> type(1) # pass number to function...
<class 'int'> # ...and receive the number!
>>> type(x) # pass name to function...
<class 'int'> # ...but receive the target!
请注意,技术上,
1
也不是对象,而是对象的文字。只有对象可以传递——它不会显示它是否来自文字 1
或者,例如,数学表达式,如 2 - 1
.
关于python - 在 x = 1 中,x 和 1 都是对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62433210/