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