看完了,对数组的映射和过滤有了比较清楚的了解,这么快就看到了最爱用的三元运算,这章的例子非常有用,我默了出来
Python代码
- def setRunEnv():
- import sys
- sys.path.append('D:\project\mypy')
- setRunEnv()
- def info(object, spacing = 10, collapse = 1):
- methodList = dir(object)
- methodList = [method for method in methodList if callable(getattr(object, method))]
- processFunction = collapse and (lambda s:" ".join(s.split())) or (lambda s:s)
- return "\n".join(["%s%s" % (method.ljust(spacing),
- processFunction(str(getattr(getattr(object, method), "__doc__"))))
- for method in methodList])
- li = []
- #print info(li, 20, 0)
- print 1 and 'ok' or 'no'
- print 1 and '' or 'no'
- print 1 and [''] or 'no'
PHP代码
- <?php
- $a = 1;
- $b = '';
- $a == 1 && ($b = 'ok') || ($b = 'no');
- echo $b;
- ?>
Python代码
- a==1 and b='ok' or b='no'
第二个表达式一定不能为 false,否则完蛋。。


