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