[python学习手册]if语句
2014-09-01 13:26
459 查看
1、是-否:
2、是-否-其它:
3、类'switch':
a、print(branch.get('abc','Bad Choice'))
b、try方法
4、调用类似钩子函数:
if test1: statement1 else: statement2
2、是-否-其它:
if test1: statement1 elif test2: statement2 elif test3: statement3 else: statement4
3、类'switch':
choice='def' branch={ 'abc':1.80, 'def':1.92, 'hij':2.89 }[choice]其它的方法:
a、print(branch.get('abc','Bad Choice'))
b、try方法
try: print(branch[choice]) except KeyError: print('Bad choice')
4、调用类似钩子函数:
def function(): ... def default(): ... branch = {'spam': lambda: ..., 'ham': function, 'eggs': lambda: ...} branch.get(choice, default)()
相关文章推荐
- 【Python学习】python学习手册--第十二章 if语句与语法规则
- python 学习笔记 if语句
- Python学习入门基础教程(learning Python)--3.2 if-else分支语句 .
- 学习Python语言---If语句
- python 学习之cmd下的if语句
- Python新手学习基础之条件语句——if/else语句
- Python学习入门基础教程(learning Python)--3.2 if-else分支语句
- Python学习笔记四:if语句
- Python3 学习手册(二) 流程控制语句
- 【Python 学习手册笔记】Python 语句简介
- Python学习笔记(二)if语句的简单用法
- Python学习笔记(九):if、while、for语句
- Python学习(3)——if语句
- Python学习笔记四:if语句
- python学习手册笔记--第10章--语句简介--第11章--复制_表达式_打印
- Python学习入门基础教程(learning Python)--3.1Python的if分支语句 .
- 《Python 学习手册4th》 第十章 Python语句简介
- 《Python 学习手册4th》 第十二章 if测试和语法规则
- Python新手学习基础之条件语句——if/else语句
- Python新手学习基础之条件语句——if/else语句