Python Basic Learning Notes (iv) statement

Source: Internet
Author: User

Resources:

1. Basic Python Tutorial

2. http://www.runoob.com/python/python-chinese-encoding.html

3. http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000

  ? conditional Statements

The usage examples of conditional statements are as follows:

#!/usr/bin/python#-*-coding:utf-8-*-#Example 2:elif usageNum= 5ifNum >= 0 andNum <= 1:#determine if the value is between 0~1    Print 'between 0~1'        elifnum = = 2:    Print '2'elifnum = = 3:    Print '3'elifnum = = 4:Print '4'Else:    Print 'Invalid Value'     #output when conditions are not true

  ? While Loop statement

the use instance of the while loop statement is as follows:

 while 1:          #  loop condition 1 must be set to    print i         #  output 1~10    i + = 1    if i >:     #  when I is greater than 10 o'clock jump out of loop break        

? For Loop statement

 #  !/usr/bin/python  #  -*-coding:utf-8-*- fruits  = [ Span style= "color: #800000;" > '  banana   ' ,  apple   ' ,   

Example 2:

#!/usr/bin/python#-*-coding:utf-8-*- forLetterinch 'Python':#First Instance   ifLetter = ='h':      Continue   Print 'Current Letter:', Lettervar= 10#a second instance whilevar >0:var= Var-1ifvar = = 5:      Continue   Print 'Current variable Value:'Var

? Pass Statement

The pass statement is an empty statement that guarantees the integrity of the program structure.

#!/usr/bin/python#-*-coding:utf-8-*-#output Python for each letter forLetterinch 'Python':   ifLetter = ='h':      Pass      Print 'This is a pass block .'   Print 'Current Letter:', letter

Python Basic Learning Notes (iv) statement

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.