python中的赋值符号实际上是什么?

编程入门 行业动态 更新时间:2024-10-26 18:22:49
本文介绍了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文档中找到正确的答案. =和朋友被视为定界符.来源: 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中的赋值符号实际上是什么?

本文发布于:2023-11-02 14:02:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552601.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:赋值   符号   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!