Explanation of if nested command instance in python

  • 2021-09-11 20:48:30
  • OfStack

1. The order in which the nested commands are executed by the computer

Indent the same commands at the same level. In step 1, the computer executes the commands one by one in sequence.

1. Assign a value to score first;

2. Because if and else can only leave one mutually exclusive relationship, and only one code block will be executed under if and else, the computer should judge that the assigned content meets "score" > = 60 "or" score < 60 "-If the condition of if is met, the contents under if indentation are executed.

2. if nesting

if nesting means that an if condition is written internally under the existing if condition.


score=26
if score>=60:
 print(' You have passed the exam ')
 if score>=80:
  print(' You are very excellent ')
 else : 
  print(' You just 1 Be like ')
else:
 print(' Fail ')  
 if score<30:
  print(' Slag ')
 else:
  print(' It can also be rescued 1 Under ')

Extension of knowledge points:

The syntax for nesting if... elif... else structures can be:


if expression1:
statement(s)
if expression2:
statement(s)
elif expression3:
statement(s)
else
statement(s)
elif expression4:
statement(s)
else:
statement(s)

Related articles: