1.Python’s Statements
Statement rule special cases
a = 1; b = 2; print(a + b) # Three statements on one line chain together only simple statements
mylist = [1111, #cross multiple lines
2222,
3333]
if (A == 1 and
B == 2 and
C == 3):
print('spam' * 3)
Block rule special case
if x > y: print(x) #single-line if statements, single-line while and for loops
while True:
reply = input('Enter text:')
if reply == 'stop': break
try:
num = int(reply)
except:
print('Bad!' * 8)
else: #else part to be run if no exception is raised in the try part
print(num ** 2)
print('Bye')
本文深入探讨了Python编程中的语法规则、特殊用例及实际应用案例,涵盖了多行语句、条件判断、循环控制、异常处理和交互式输入等核心概念。
494

被折叠的 条评论
为什么被折叠?



