if语句写在1行
在if语句中,如果block只有一个,则if(或elif或else)可以与block的主体写在同一行:
if something: somefunc()
else: otherfunc()
但这是不鼓励的形式的问题。
有条件表达式:
a if cond else b
但这是一个表达式,不是一个语句。
在if语句中,如果block只有一个,则if(或elif或else)可以与block的主体写在同一行:
if something: somefunc()
else: otherfunc()
但这是不鼓励的形式的问题。
有条件表达式:
a if cond else b
但这是一个表达式,不是一个语句。