Python的三种结构顺序、分支、循环某单次测试的流程:测试结果?True处理接下来False:else处理yesno例子:#coding=utf-8__author__='zyt'#if-elif-elsex=0ifx<0:print'xlessthan0'elifx==0:print'xequalsto0'else:print'xlargethan0'#whilex=0whilex<5:printxx+=1else:x=0print'whilestatementover,nowx=%d'%x#for-inforyinrange(10,19,3):printy, #print默认会每行增加一个换行符,print句后加一个逗号就不会了else:print'\nforstatementover'运行结果:E:\python_workspace>,nowx=0101316forstatementoverl1l2l3l4l5l6l7l8l9l10l11l12l13l14l15l16l17l18l19l20l21l22l23l24l25l26l27l28l29l30l31l32l33l34l35l36l37l38l39l40try…语句语法“try”“:”suite (“except”[expression[(“as”|“,”)identifier]]“:”suite)+ [“else”“:”suite] [“finally”“:”suite]Theoptional else clauseisexecutedifandwhencontrolflowsofftheendofthe try clause.*try异常?尝试成功的处理*else处理*finally*except捕获的处理yesno例子:#coding=utf-8__author__='zyt'defmy_func(denominator):try:
Python例题 来自淘豆网m.daumloan.com转载请标明出处.