python 一行寫幾條語句
一行輸入多個語句,用分號隔開
print('hello');print('world')
一條語句分多行書寫
一語句多行有兩種形式。
一種是括號,包括小括號、中括號和大括號。
適用於條件判斷:
(1<2
and 1==3
)
這種形式尤其在條件表達式中比較好用,如:
level=('D' if 0<=score<60 else
'C' if 60<=score<80 else
'B' if 80<=score<90 else
'A' if 90<=score<=100 else
'請輸入0-100之間的數值')
但不適用於函數,如下面代碼會報錯:
print('hello
world'
)
另一種是反斜杠
1<2\
and 1==3
REF
https://blog.csdn.net/weixin_43217427/article/details/107320600