Python的三种结构顺序、分支、循环某单次测试的流程:测试结果?True处理接下来False:else处理yesno例子:#coding=utf-8__author__='zyt'#if-elif-elsex=0ifx0:print'xlessthan0'elifx==0:print'xequalsto0'else:print'xlargethan0'#whilex=0whilex5:printxx+=1else:x=0print'whilestatementover,nowx=%d'%x#for-inforyinrange(10,19,3):printy,#print默认会每行增加一个换行符,print句后加一个逗号就不会了else:print'\nforstatementover'运行结果:E:\python_workspacepythontest.pyxequalsto001234whilestatementover,nowx=0101316forstatementover12345678910111213141516171819202122232425262728293031323334353637383940try…语句语法“try”“:”suite(“except”[expression[(“as”|“,”)identifier]]“:”suite)+[“else”“:”suite][“finally”“:”suite]Theoptionalelseclauseisexecutedifandwhencontrolflowsofftheendofthetryclause.*try异常?尝试成功的处理*else处理*finally*except捕获的处理yesno例子:#coding=utf-8__author__='zyt'defmy_func(denominator):try:a=1/denominatorprint'trystatement'except:print'exceptstatement'a=999999else:print'elsestatement'finally:print'finallystatement'print'functionend'returnaif__name__=='__main__':printmy_func(1)print'---------'printmy_func(0)运行结果:E:\python_workspacepythontest.pytrystatementelsestatementfinallystatementfunctionend1---------exceptstatementfinallystatementfunctionend999999