我有 if 语句
if "1111111" in players or "0000000" in players or "blablabla" in players:
do something
简而言之怎么写?
我有 if 语句
if "1111111" in players or "0000000" in players or "blablabla" in players:
do something
简而言之怎么写?
您可以使用any()
:
things = ["1111111", "0000000", "blablabla"]
if any(thing in players for thing in things):
if any(x in players for x in ("1111111", "0000000", "blablabla")):
# do something
如果您要进行大量此类成员资格检查,您可以考虑将其制作players
成set
不需要潜在地遍历每次检查的整个序列。
if any(a in players for a in list_of_tests):
#something
pass
如果您使用numpy.any()
,则需要先将生成器转换为列表。
if np.any([a in players for a in list_of_tests]):
#something
pass