大多数资源在线调用=(和+ =,-=等)用于赋值运算符(对于python).在大多数语言中这是有意义的,但是在python中却没有.一个运算符采用一个或多个操作数,返回一个值,并形成一个表达式.但是,在python中,赋值不是表达式,并且赋值不会产生值.因此,=不能是运算符.
Most sources online call = (and +=, -=, etc...) an assignment operator (for python). This makes sense in most languages, however, not in python. An operator takes one or more operands, returns a value, and forms an expression. However, in python, assignment is not an expression, and assignment does not yield a value. Therefore, = cannot be an operator.
那到底是什么?在x = 0这样的语句中,x是一个标识符,0是一个数字文字,但是我不知道该怎么称呼"=".
So what exactly is it? In a statement like x = 0, x is an identifier, 0 is a numeric literal, but I don't know what to call "=".
推荐答案我能够在官方python文档中找到正确的答案. =和朋友被视为定界符.来源: docs.python/3/reference/lexical_analysis. html#delimiters
I was able to find the correct answer in the official python documentation. = and friends are considered delimiters. source: docs.python/3/reference/lexical_analysis.html#delimiters
关于表达式的python docs参考未将=定义为运算符或构成表达式.来源: docs.python/3/reference/expressions.html
python docs reference for expressions does not define = as an operator nor as forming an expression. source: docs.python/3/reference/expressions.html
但是,它确实使用自己的生产规则定义了赋值语句,规则中明确包含=.来源: docs.python/3/reference/simple_stmts.html#assignment-statements
It does, however, define assignment statements with their own production rule with = explicitly included in the rule. source: docs.python/3/reference/simple_stmts.html#assignment-statements
所以最后的答案是,根据官方消息,它是定界符".
So the final answer is that it is "delimiter" according to official sources.
更多推荐
python中的赋值符号实际上是什么?
发布评论