Process Control if
If statement
If expression:
Statement (s)
Else
Else statement:
If statement, Else statement
If expression:
Statement (s)
Else
Statement (s)
Elif statement:
If expression1:
Statement1 (s)
Elif expression2 (s):
Statements2 (s)
Else
Statement2 (s)
Note: Python uses indentation as a method of grouping its syntax, and it is recommended to use 4 spaces
A logical value (BOOL) contains two values:
True: Represents non-empty quantities (for example: string,tuple,list,set,dictonary) for all non-zero.
False: Represents 0,none, empty amount, etc., including empty tuples, empty lists, empty dictionaries.
[[Email protected] ~]# vim 1.py#!/usr/bin/pythonscore = int (Raw_input ("please input you score ")) if score >= 90: print ' A ' print ' Very good ' elif score >= 80: print ' B ' print ' good ' elif score >= 70: print ' C ' print ' pass ' else : print ' D fail ' print ' End ' [[email protected] ~]# python 1.py please input you score90avery goodend[[email protected] ~]# python 1.py please input You score80bgoodend[[email protected] ~]# python 1.py please input you score70cpassend[[email protected] ~]# python 1.py please input you score10d failend
[[email protected] ~]# vim 2.py #!/usr/bin/pythonyn = raw_input ("Please input [yes/no]") yn = yn.lower () if yn = = ' y ' or yn = = ' Yes ': print "program is running" elif yn = = ' n ' or yn = = ' no ': print "program was exit" Else:print "please Inpu t [yes/no] "[[email protected] ~]# python 2.py * input [Yes/no]yesprogram is running[[email protected] ~]# python 2.py please input [Yes/no]noprogram is exit
This article comes from "Plum blossom fragrance from bitter cold!" "Blog, be sure to keep this provenance http://daixuan.blog.51cto.com/5426657/1773603
Python Learning Note 3-Process Control if, for, while