Python—Multiple statements in one line and multiple lines in one sentence

1. One line with multiple statements

Enter multiple sentences in one line, separated by semicolons

print('hello');print('world')

2. One statement with multiple lines

There are two forms of one statement with multiple lines.

  • One is parentheses, including parentheses, square brackets and curly brackets.

Applicable to condition judgment :

(1<2
and 1==3
)

This form is especially useful in conditional expressions, such as: 

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之间的数值')

But it does not apply to functions , such as the following code will report an error:

print('hello
world'
)
  • The other is the backslash
1<2\
and 1==3

 

Guess you like

Origin blog.csdn.net/weixin_43217427/article/details/107320600