Python 中的 = 和 == 运算符有什么区别?
pythonserver side programmingprogramming更新于 2025/8/6 10:20:17
在 Python 中,= 符号被定义为赋值运算符。它要求其左侧有一个变量,右侧有一个表达式。右侧表达式的值被赋给左侧的变量。表达式和变量名不能互换。
>>> a=10 >>> b=20 >>> c=a+b >>> a,b,c (10, 20, 30) >>> a+b=c SyntaxError: can't assign to operator
== 符号是比较运算符,称为等于运算符。如果两边的操作数相等则返回 true,否则返回 false
>>> 10+2 == 10 False >>> (10+2) == 12 True >>> 'computer' == 'Computer' False >>> 'computer' == "computer" True
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

