python中的赋值符号实际上是什么? [英] What actually is the assignment symbol in python?

查看:524
本文介绍了python中的赋值符号实际上是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大多数资源在线调用=(和+ =,-=等)用于赋值运算符(对于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文档中找到正确的答案. =和朋友被视为定界符.来源: https://docs.python.org/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: https://docs.python.org/3/reference/lexical_analysis.html#delimiters

关于表达式的python docs参考未将=定义为运算符或构成表达式.来源: https://docs.python.org/3/reference/expressions.html

python docs reference for expressions does not define = as an operator nor as forming an expression. source: https://docs.python.org/3/reference/expressions.html

但是,它确实使用自己的生产规则定义了赋值语句,规则中明确包含=.来源: https://docs.python.org/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: https://docs.python.org/3/reference/simple_stmts.html#assignment-statements

所以最后的答案是,根据官方消息,它是定界符".

So the final answer is that it is "delimiter" according to official sources.

这篇关于python中的赋值符号实际上是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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