Python3 from zero to single _ something fun, python3
Here we will introduce four:
1. Implementation progress bar
2. Copy in Depth
3. Ternary operation
4. format to upload the dictionary
1 # progress bar 2 import time 3 for I in range (10): 4 time. sleep (1) 5 print ('*', end = '', flush = True) 6 # The default end parameter is '\ n ', therefore, if no value is passed, a new line is generated by default. 7 # flush indicates printing once in a loop. The default parameter is 'false'. If this parameter is set to True, 10x8 records will be printed together in 10 seconds. Now the above Code prints a * 9 10 # copy every second. Deep copy means that the memory address is different, the shortest copy is that the memory address of the variable is the same. 11 a = B = c = 'hahaha' 12 print (id (a), id (B), id (c )) # All memory addresses are the same 13 c = 'xixi' 14 print (id (a), id (B), id (c )) # c memory address is different 15 e = f = g = ['hahaha', 123] 16 print (id (e), id (f), id (g )) # The memory address is the same as 17 GB. append ('xixi') 18 print (id (e), id (f), id (g )) # The memory addresses are still the same. 19 20 # The above direct a = B = c is a light copy, for deep copy, use the copy Module 21 import copy22 a = B = c = 'hahaha' 23 print (id (a), id (B), id (c )) # The memory address is the same 24 d = copy. deepcopy (a) 25 print (id (a), id (B), id (c) # c memory address is different, this is the deep copy 26 27 # ternary computation 28 a = 829 B = 230 c = B if B> a else a # This is the ternary computation 31 print (c) 32 33 # format upload dictionary 34 print ('{name}, {age }'. format (age = 18, name = 'xg') 35 dic = {'age': 18, 'name': 'xg'} 36 print ('{name }, {age }'. format_map (dic) # upload a dictionary after format_map. 37 # The output result is the same.