Python Learning Note 3-Process Control if, for, while

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.