print(input()+ input())如何在python中工作?没有变量分配? [英] How print(input() + input()) works in python ? Without variable assignment?
问题描述
a = input()
b = input()
print(a+b)
这可以写成 print(input()+ input())
即可.它是如何工作的?输入被临时存储在哪里?
This can be written as
print(input()+input())
and it works.
How does it work? Where are the inputs are stored temporarily?
推荐答案
前提: input()
只是一个常规函数,该函数会阻塞直到用户键入内容为止.完成后,数据被评估并返回.
Premise: input()
is just a normal function that blocks until the user types something in. Once that is done, the data is evaluated and returned.
撇开这些内容,您的声明由以下几部分组成:
With that set aside, your statement is composed of several parts:
print(...)
是一个函数调用,它打印括号内的表达式的结果.
print(...)
is a function call that prints the result of the expression that is between its parentheses.
表达式为 input()+ input()
.由于 operator()
的优先级高于 operator +
,因此将在求和之前对两个 input()
调用进行求值.
The expression then is input() + input()
. Since the operator()
has a higher precedence than operator+
, the two input()
calls will be evaluated before the sum.
input()
的结果是未命名的临时变量,仅在评估完整表达式之前存在, em>.一旦执行 +
,临时变量将有效丢失(并最终被垃圾回收).
The result of an input()
is an unnamed temporary variable that exists only until the full expression is evaluated. Once the +
is executed, the temporary variables are effectively lost (and will be garbage collected eventually).
这篇关于print(input()+ input())如何在python中工作?没有变量分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!