python 中使用 if a == b == c: pass;` 是否有副作用?
if a == b == c:
# do something
我们假设 a, b, c 是字符串变量。当且仅当所有三个字符串都相等时,如果我使用上面的代码片段执行 # do some
,是否会有任何可能的副作用?
我这样问是因为我必须相互检查三个变量,并且我遇到了很多情况:
if a == b == c:
# do something
elif a == b != c:
# do something
elif a != b == c.
# do something
etc...
也许有更好的方法来编码?
if a == b == c:
# do something
Let's assume a, b, c
are string variables. Are there any possible side effects if I use the snippet above to execute # do something
if and only if all three strings are equal?
I am asking because I have to check three variables against each other and I get many cases:
if a == b == c:
# do something
elif a == b != c:
# do something
elif a != b == c.
# do something
etc...
Perhaps there is a better way to code this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在您以这种方式使用之前,应该不会有任何副作用。
但请注意以下事项:
因为它会破坏链接,并且您将比较
True
或False
和c
值)。There should be no side effects until you use it in a such way.
But take care about things like:
since it will break chaining and you will be comparing
True
orFalse
andc
value).来自文档:
应该没有副作用。
From the documentation:
There should be no side effects.
对 x!=y!=z 有什么评论吗?
我可以用愚蠢的方法来得到正确的答案。
is there any comment on x!=y!=z ?
i could use the stupid way to get a correct answer.