while loop control of the process and copy depth

First, copy depth
   
    . 1, a shallow copy: the listing is the memory address of the first layer completely without distinction a new copy of the list.
   
    Example:
   
    List1 = [
        'Egon',
        'LXX',
        [1,2]
    ]
    list3=list1.copy()
    print(list3)
    print(id(list1))
    print(id(list3))
    print(id(list1[0]),id(list1[1]),id(list1[2]))
    print(id(list3[0]),id(list3[1]),id(list3[2]))
    Experiment 1: For immutable types of assignments are created new value, so that the original list of index point to the new
    memory address, and will not affect the new list
    List1 [0] = 'EGON'
    List1 [1] = 'LXX'
    list1 [2] = 123
    Experiment 2: But for the variable type, we can change the value of the variable type is included, but the same memory address
    that is pointing to the original list of index still point to the memory address, then followed with a new list by
    the impact, as follows
    list1 [ 2] [0] = 111
    List1 [2] [. 1] = 222
    Print (List1)
    Print (list3)
    Integrated Experiments 1 and 2 can be drawn, change to operate the new list with the original copy of the list in order to get the full independence opened
    there must be a variable types can be distinguished with the type of immutable copy mechanism, which is a deep copy
    2, deep copy: After thoroughly understand shallow copy and deep copy on a good understanding, a deep copy is to re-open up a space in memory,
    popular speak is, a deep copy is redefining a variable, not a cent in the previous relationship, so change the contents inside, and the original will not change.
   
    Example: Import Copy
    List1 = [
        'Egon',
        'LXX',
        [1,2]
    ]
    list3=copy.deepcopy(list1)
    print(id(list1))
    print(id(list3))
    print(list3)
             Immutable immutable Variable
    Print (ID (List1 [0]), ID (List1 [. 1]), ID (List1 [2]))
    Print (ID (list3 [0]), ID (list3 [. 1]), ID (list3 [2]))
    '' '
    4,497,919,088 4,498,367,856 4498449216
    4497919088 4,498,367,856 4498595328
    ' ''
    Print (list3)
    Print (ID (List1 [2] [0]), ID (List1 [2] [. 1]))
    Print ( id (list3 [2] [0 ]), id (list3 [2] [1]))
    list1[0]='EGON'
    list1[1]='LXX'
    List1 [2] [0] = 111
    List1 [2] [. 1] = 222
    Print (List1)
    Print (list3) to be modified,
Two, while cycle
  
    1, what is the while loop: is a type of python in the loop structure.
       Why use cycle: to repeat certain human moment to do something, so the program must have the appropriate mechanisms to control the computer, like people, have the ability to do things in this cycle.
    2, while loop syntax:
        while condition:
               Code 1
               Code 2
               Code 3
    while operating steps:
    Step 1: If the condition is true, the execution code from top to bottom 1,2,3 ...
    Step 2: determination condition again completed for the last one code is repeated if the condition of step 1 Treu if the condition is False, the end of the cycle.
    2, while circulation Applications:
    Case I: user authentication program
         
    Case II: while + using the break
    after using a while loop, the code does more streamlined, but the problem is after the user enters the correct username and password can not be the end of the cycle, how does it off the end of a cycle which?
    Need to use a break !
          
    Case 3: Case 3: while nested loop + break
    if the while loop nested many layers, each layer in order to exit the loop you need to have a break in each layer cycle.
          
    Case Four: while using a nested loop + tag
    for a while loop nested multi-layered, if our purpose is clear is that to a certain - - layer loop to exit all layers, there is a real trick, let all the while loop the
    conditions are the same with a variable, the variable initial value True, - but a - this variable to the value of the layer False, then the end of the cycle all layers.
         
    Case 5: while + continue using the layer break on behalf of the end of the cycle, and then continue to the end of this cycle, the next cycle direct access.
        
    Six cases: while + using else's
    in the back while loop, we can with the else statement, when the while loop properly completed and there should be break stay of execution, they would perform behind the else statement, the
    order that we can use else to verify cycle is completed properly.
        
    If the execution is break, it will not execute the else statement.
      

Guess you like

Origin www.cnblogs.com/200024mc/p/12452775.html