读书人

python 3目运算(转)

发布时间: 2013-10-10 14:14:51 作者: rapoo

python 三目运算(转)
Python代码

  1. >>>?a?=?'abc'??
  2. >>>?b?=?'efg'??
  3. >>>?1==0?and?a?or?b??
  4. 'efg'??
  5. >>>?1>2?and?a?or?b??
  6. 'efg'??
  7. >>>?1<2?and?a?or?b??
  8. 'abc'??

?在如: a = '' 的话

?

Python代码
  1. >>>?a?=?''??
  2. >>>?1<2?and?a?or?b??
  3. 'efg'??
  4. >>>?1>2?and?a?or?b??
  5. 'efg'??

?结果与我们要的不符.这个东西具体可以参考 dive?into python?Python代码

  1. >>>?(1<2?and?[a]?or?[b])[0]??
  2. ''??
  3. >>>?(1>2?and?[a]?or?[b])[0]??
  4. 'efg'??

?这些基础还得多看看python语法

读书人网 >perl python

热点推荐