如何在Python中的多行if语句中注释每个条件?
如果您用括号括住多行if语句,则可以直接执行此操作。例如,
if (cond1 == 'val1' and cond2 == 'val2' and # Some comment cond3 == 'val3' and # Some comment cond4 == 'val4'):
但是,如果您尝试在没有括号的情况下执行此操作,则这是不可能的。例如,以下代码将给出错误:
if cond1 == 'val1' and \ cond2 == 'val2' and \ # Some comment cond3 == 'val3' and \ # Some comment cond4 == 'val4':