Python if .. else, pythonif .. else
I. Introduction
1. Complete Form
If <condition judgment 1>: <execution 1> elif <condition Judgment 2>: <execution 2> elif <condition judgment 3 >:< execution 3> else: <execution 4>
Note: 1. the colon after the if clause cannot omit ":", and four spaces are required for the indent rule.
2. if the value of True is determined from the top down. if the value of True is determined from the top down, the statement under the corresponding judgment is executed. no matter whether the subsequent judgment is True or not
2. Example
Determines whether it is adult
#!/usr/bin/env python3# -*- coding: utf-8 -*-age=20if age>18: print ('adult')elif age>7: print ('teenager')else: print ('kid')
The final running result is "adult", and elif age> 7 does not meet the conditions, which is the second note above, when the conditional judgment is True, no further judgment will be made.
Note: Author: pursuer. chen Blog: http://www.cnblogs.com/chenmh All essays on this site are original. You are welcome to repost them. However, you must indicate the source of the article and clearly give the link at the beginning of the article. Welcome to discussion |