Python中if-else语句的多种写法
2016-04-27 20:05
246 查看
a, b, c = 1, 2, 3
1. 常规
if a>b: c = a else: c = b
2. 表达式
c = a if a>b else b
3. 二维列表
c = [b,a][a>b]
4. (条件表达式 and
[真时取值] or
[假时取值])[0]
c = a>b and a or b
参考链接:http://www.open-open.com/lib/view/open1346511811678.html
相关文章推荐
- python+selenium 简单尝试
- Python正则表达式汇总
- windows下安装gulp-sass编译不过去报错的解决方案;
- Python Web后端处理业务
- Notepadpp的Python Script插件
- Ant、Gradle、Python三种打包方式的介绍
- 常用的 Python 爬虫技巧总结
- Python logging模块详解
- Python开发的10个小贴士
- Python数据分析学习笔记五
- Python 主要模块和常用方法简览
- python常用50个模块
- python学习3
- Python学习(三)入门技巧
- python random
- Ubuntu14.04中安装Anaconda2-4.0.0的方法
- Python基本语法[二]
- [python]新手写爬虫v2.5(使用代理的异步爬虫)
- python-初学入门
- webdriver for python模拟键盘操作