Python basis of the range, function, while circulation

# Range function
- generating an ordered sequence
- generating a digital queue can be customized

. 1  # range Case 1 
2  # generates a number from sequence 1 to 100 
3  # is the range to generate a sequence of two series left includes a right is not included 
. 4 dig_list = range (1,100 )
 . 5  for DIG in dig_list:
 . 6      IF DIG% 2 = . 1 = :
 . 7          Continue 
. 8          
. 9      the else :
 10          Print (DIG)
1 for one in range(1,10):
2     print(one)
# Function 
- the function is a code form
 - function should be able to complete a particular job, and generally a function of the value of a job done (things to be understood as a beginning and an end, so that a program can be made to form a closed loop function is not otherwise significance)
 - some languages, sub-functions and procedures the two concepts, popular explanation is called the function returns the result, the result of no return process is called, Python no distinction
 - the use of functions
     - functions use must first define
     - using a function known as transfer
# Define a function 
# is only defined if not executed 
# behind 1.def keyword followed by a space 
# 2. The function name, their own definition, named need to follow the naming convention, just to name the big hump class with the 
# 3 behind brackets colon and should not be spared, brackets can have arguments 
# All the code within the function to indent 4

DEF FUNC ():
     Print ( " love life " , " love LAF " )
     Print ( " I'm a function of personality " )
 Print ( " function is over " ) 
FUNC ()

# While loop
- a loop
- Indicates when the condition is satisfied when he cycles; applicable to not know the specific number of cycles of time, but can determine the case of a condition exists on the cycle
- while syntax:
the while conditional expression:
statement block
# another method of expressing
an expression while condition:
statement block. 1
the else:
statement block 2

1  # If the annual interest rate is 6.7% annual principal and interest roll is years away money to double it? 
2 benqian = 100000
 . 3 year = 0 # Number of required storage 
. 4  the while benqian <200000 :
 . 5      benqian = benqian * (. 1 + 0.067 )
 . 6      year + =. 1
 . 7  Print (year)
 . 8  
. 9  # Case 2 
10  the while benqian <200000 :
 . 11      benqian benqian * = (. 1 + 0.067 )
 12 is      year +. 1 =
 13 is  
14  the else :
 15      Print (year)

 

Guess you like

Origin www.cnblogs.com/liutan/p/12505355.html
Recommended