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



原文地址:https://www.cnblogs.com/emanlee/p/15187932.html