python控制流

条件语句:
if expression:
    statements
elif expression:
    statements
elif expression:
    statements
...
else:
    statements

if expression:
    pass            # 不做任何事
else:
    statements 


循环:
第一种while:
while expression:
    statements

for i in s:
    statements

第二种for:
for x,y,z in s:
    statements


异常:
try:
   do something
except IOError, e:
   # 处理 I/O error
   ...
except TypeError, e:
   # 处理 Type error
   ...
except NameError, e:
   # 处理 Name error


try:
   do something
except (IOError, TypeError, NameError), e:
   # 处理 I/O, Type, 或 Name errors


try:
     statements
except LookupError:     # 捕获 IndexError 或 KeyError
     statements
或
try:
     statements
except StandardError:   # 捕获任何内建的异常类型
     statements

你可能感兴趣的:(java,python)