Python branch structure

two branches

1 General form

2if else compact form

             <expression 1> if condition is true else <expression 2>

multi-branch


Relational operators and or not == >= <= > <


exception handling

Important program tips:

1 Number of positioning lines

2 Exception type: a content reminder

two basic ways

1try:

        <statement block one>

 except:

        <statement block two>

2try:

        <statement block one>

except exception type:

        <statement block two>

Advanced usage:

try:

    <statement block one>

except:

    <statement block two>

else:

    <statement block three> (execution without exception)

finally:

    <statement block four> (statement block four must be executed)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325871634&siteId=291194637