Python3 from zero to single _ something fun, python3

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.