python 一行寫多個語句


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




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM