if expression:
if_suite
如果表达式非0值,则代码组if_suite 被执行;否则就去执行下一条语句
>>> if 3 > 1: ... print ‘ok‘ ... print ‘yes‘ ... ok yes >>> if 3 > 1: ... print ‘ok‘ ... print ‘yes‘ File "<stdin>", line 3 print ‘yes‘ ^ IndentationError: unexpected indent >>> if 3: ... print ‘ok‘ ... ok >>> if 0: ... print ‘ok‘ ... >>> if ‘‘: ... print ‘ok‘ ... >>> if ‘ ‘: ... print ‘ok‘ ... ok >>> if None: ... print ‘ok‘ ... >>> if 3 > 10: ... print ‘ok‘ ... else: ... print ‘no‘ ... no
原文:http://www.cnblogs.com/weiwenbo/p/6552833.html