有人可以向我解释一下吗
..Python 中 = 和 == 符号的区别?即提供每个使用时的示例,以便两者之间不会混淆?
.. the difference between the = and the == signs in Python? i.e provide examples when each is used so there's no confusion between the two?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
= 用于分配变量,即
number = 30
- “number”变量现在保存数字 30。== 用作布尔运算符来检查变量是否彼此相等,即
1 == 1
将返回true
,1 == 2
将返回false
= is used to assign variables ie
number = 30
- the "number" variable now holds the number 30.== is used as a boolean operator to check whether variables are equal to each other ie
1 == 1
would givetrue
and1 == 2
would returnfalse
=
是赋值,==
是相等。=
is assignment,==
is equality.=
是赋值,你可以用它来给变量赋值。str = "hello"
将“hello”分配给str
,因此如果您要获取str
的值,它将是一个 <代码>你好。==
是相等比较,您用它来比较两个值。在该代码中,您想查看
str
的值是否等于字符串“hello”,如果我们按上面的方式分配它,这将导致打印“equal”。=
is assignment, you would use it to give a value to a variable.str = "hello"
assigns "hello" tostr
, so that if you were to get the value ofstr
, it would be ahello
.==
is equality comparison, you use it to compare two values.In that code you want to see if the value of
str
is equal to the string "hello", and if we assigned it as above, this would result in "equal" being printed.“==”检查是否相等。 “=”用于赋值。例如
v="100"
然后检查v
是否为 100,v==100
"==" is checking for equality. "=" is for assignment of values. eg
v="100"
Then to check whetherv
is 100,v==100