当我编写如下代码时,我得到了深深的缩进
match = re.search(some_regex_1, s)
if match:
# do something with match data
else:
match = re.search(some_regex_2, s)
if match:
# do something with match data
else:
match = re.search(soem_regex_3, s)
if match:
# do something with match data
else:
# ...
# and so on
我试图重写为:
if match = re.search(some_regex_1, s):
# ...
elif match = re.search(some_regex_2, s):
# ...
elif ....
# ...
...
但 Python 不允许这种语法。在这种情况下,我应该怎么做才能避免深度压痕?