lygyh9985825 发表于 2018-8-10 10:03:13

python and or-11876896

类似三目表达式的用法:bool? a : b  >>> a ='first'
  >>> b ='second'
  >>>1and a or b   # 等价于 bool = true时的情况
  'first'
  >>>0and a or b   # 等价于 bool = false时的情况
  'second'
  >>> a =''
  >>>1and a or b   # a为假时,则出现问题
  'second'
  >>>(1andor)# 安全用法,因为不可能为假,至少有一个元素
  ''
  >>>
页: [1]
查看完整版本: python and or-11876896