#1. #A:顶层代码必须位于第一栏开始,否则将产生错误 #B:不要混用制表符和空格来产生缩进 value = ( 's' #value = 'szn' 'z' 'n' ) value = ('a' #value = 'abcd' 'b' 'c' 'd' ) #编译错误 ''' value = ( 's' #value = 'szn' 'z' 'n' ) ''' #2. #A:python中的布尔运算符不是 && || ! 而是 and or not,具有短路求值属性 #B:and or 总是返回对象,不是运算符左侧的对象就是右侧的对象 #C:or返回第一个为真的操作数(当表达式结果为True时),或者最后一个假的操作数(当表达式结果为False时) #D:and返回第一个假的对象(当表达式结果为False时),或者最后一个真的对象(当表达式结果为True时) value = 's' if True else 'z' #value = 's' value = 's' if False else 'z' #value = 'z' value = True and [1, 2] or 'z' #value = [1, 2] value = True and [] or 'z' #value = z value = True and [] or '' #value = value = '' value = False and 'y' or {1:3} #value = {1: 3} value = False and 'y' or {} #value = {} value = 's' or 'z' and 'n' #value = 's' value = ('s' or 'z') and 'n' #value = 'n'