python是否使用`if a == b == c:pass;`有副作用? [英] Are there sideeffects in python using `if a == b == c: pass;`?

查看:177
本文介绍了python是否使用`if a == b == c:pass;`有副作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if a == b == c:
    # do something

让我们假设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?

推荐答案

除非您以这种方式使用它,否则应该没有副作用.

There should be no side effects until you use it in a such way.

但是请注意以下事项:

if (a == b) == c:

因为它将断开链接,因此您将比较TrueFalsec值.)

since it will break chaining and you will be comparing True or False and c value).

这篇关于python是否使用`if a == b == c:pass;`有副作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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