码迷,mamicode.com
首页 > 编程语言 > 详细

if-else(python)的几种写法

时间:2014-12-04 13:39:57      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:http   ar   sp   on   bs   html   ef   时间   tt   

今天查if-else的时候发现了下面这篇文章,2、3之前都没见过,4花了一段时间才看明白(Tips:short circuit)

Python中if-else语句的多种写法

1.常规

if a>b:

    c = a

else:

    c = b

2.表达式 

c = a if a>b else b

3.二维列表

c = [b,a][a>b]

4.传说是源自某个黑客

c = (a>b and [a] or [b])[0]

if-else(python)的几种写法

标签:http   ar   sp   on   bs   html   ef   时间   tt   

原文地址:http://www.cnblogs.com/duqf/p/4142554.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!