If嵌套
# 一个随机数程序
import random
rand = random.randint(0,10)
var =input('please input a numer\n>')
var = int(var)
if var > 0:
print('This is a postive')
if ( var >= 18 ) and ( var <= 60 ):
print('You are at normal age')
elif ( var < 18 ):
print('You are too young to work!')
else:
print('You should retire')
elif var < 0:
print('This is a nagetive')
else:
print('This is zero')
在C语言中
else if被简化为 elif
只要对其,就不需要大括号
但是语句一行的末尾需要引号标识
需要借助IDE来区分逻辑关系
三目运算符
a = a if a > b else b
Python中诊治放在前面,否值放在后面