Single Branch judgment
Age = 16
If age >=: judge the sentence, determine whether the age is greater than or equal to 18, note if you want to add a space after the condition is written to add:
Print ("You are an adult")
Print ("Can go to the Internet")
Print ("Hurry Home for Dinner")
The above code is a single branch of judgment, an if is enough to meet the conditions on the printing, do not meet the directly run the following code.
Double-branch judgment
Age = 16
If age >= 18:
# if adult, print: You are already an adult and can go online
Print ("You are an adult, you can go online")
# if underage, print: Hurry home and eat, grow up fast
else: How else, pay attention to add:
Print ("Hurry home and eat, grow up fast")
And the difference between a single branch is more than one else (otherwise), the entire code means that if the conditions are met on the print "You have ... "Not satisfied on the print" hurried home ... ”
Multi-branch judgment
Score = 80
If <= score <= 100:
Print ("excellent")
Elif <= Score <: If you have if nested, you can write this form elif is equivalent to else+if abbreviation
Print ("good")
Elif <= Score < 70:
Print ("Pass")
else: There is no need to judge down here, the above is not satisfied is the failure of the
Print ("Failed")
Pay attention to the syntax structure, and later design to if nesting is this form
Forced indentation, which branch the member's code block belongs to, and the shortcut key for the retraction is Shift+tab
Python branch--if