是否可以在 Python 中简化这一点?
status = get_git_status()
for s in ("modified", "deleted", "Untracked files:"):
if s in status:
pass
是否可以在 Python 中简化这一点?
status = get_git_status()
for s in ("modified", "deleted", "Untracked files:"):
if s in status:
pass
这取决于您是否需要为每个匹配项执行操作,或者您是否只对其中任何一个匹配项感兴趣。如果您只是对其中任何一个匹配感兴趣,请使用any
:
if any(s in status for s in ("modified", "deleted", "Untracked files:")):
whatever()
如果状态“已修改”和“已删除”,您会运行两次密码吗?如果只需要运行一次,可以使用any():
status_list = ("modified", "deleted", "Untracked files:")
if any(s in status for s in status_list):
pass