1、是-否:
if test1:
statement1
else:
statement2
2、是-否-其它:
if test1:
statement1
elif test2:
statement2
elif test3:
statement3
else:
statement43、类'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中的几种情况,包括是 - 否判断、是 - 否 - 其它判断、类'switch'形式以及调用类似钩子函数的内容,聚焦于Python编程相关的条件判断和函数调用方面。
167

被折叠的 条评论
为什么被折叠?



