1 # 1 and the determination value gl_num gl_list of 2 DEF Demo (NUM, num_list): . 3 NUM = + NUM . 4 num_list + = num_list . 5 . 6 Print (NUM) # 18 is . 7 Print (num_list) # [1, 2,. 3, . 1, 2,. 3] . 8 . 9 Print ( " function to complete " ) 10 . 11 12 is gl_num. 9 = 13 is gl_list = [. 1, 2,. 3 ] 14 Demo (gl_num, gl_list) 15 Print (gl_num) # . 9 16 print(gl_list) # [1, 2, 3, 1, 2, 3]
1 # 2. Say list1, what values list2, list3 that and why 2 DEF extendlist (Val, LIS = []): . 3 lis.append (Val) . 4 return LIS . 5 . 6 List1 = extendlist (10 ) . 7 List2 = extendlist (123 , []) . 8 list3 = extendlist ( ' A ' ) . 9 10 Print (List1) # [10, 'A'] . 11 Print (List2) # [123] 12 is Print (list3) # [10 , 'a']
1 # 3. Say acts [0] value (2), and why 2 DEF makeActions (): . 3 Acts = [] . 4 for I in Range (. 5 ): . 5 acts.append ( the lambda X: I * * X) . 6 return Acts . 7 . 8 . 9 Acts = makeActions () 10 Print (Acts [0] (2)) # 16 . 11 Print (Acts [. 1] (2)) # 16 12 is Print (Acts [2] (2) ) # 16 13 Print(acts[3](2)) # 16 14 print(acts[4](2)) # 16 15 16 print("~"*50) 17 18 def makeActions(): 19 acts = [] 20 for i in range(5): 21 acts.append(lambda x, i=i: i ** x) 22 return acts 23 24 25 acts = makeActions() 26 print(acts[0](2)) # 0 27 print(acts[1](2)) # 1 28 print(acts[2](2)) # 4 29 print(acts[3](2)) # 9 30 print(acts[4](2)) # 16