Python3 from zero single row _ Some fun stuff

Source: Internet
Author: User
Tags shallow copy

  Here are four of:

1. Implement the progress bar

2. Depth copy

3. Ternary operation

4.format Format Transfer Dictionary

1 #progress bar2 Import Time3  forIinchRange (10):4Time.sleep (1)5     Print('*', end="', flush=True)6 #The end default parameter is ' \ n ', so no value is passed by default;7 #the meaning of flush here is to cycle through the print once, the default parameter is ' False ', if it is specified as true, here will be 10 seconds after printing together 10 *8 #now the above code prints a result of one per second *9 Ten #dark Copy, deep copy is the memory address is different, shallow copy is the memory address of the variable is the same OneA=b=c='haha' A Print(ID (a), id (b), ID (c))#memory addresses are the same -C='Xixi' - Print(ID (a), id (b), ID (c))#C memory address is not the same thee=f=g=['haha', 123] - Print(ID (e), id (f), ID (g))#memory addresses are the same -G.append ('Xixi') - Print(ID (e), id (f), ID (g))#memory addresses are still the same +  - #the above direct a=b=c is a shallow copy, the deep copy needs to use copy module + ImportCopy AA=b=c='haha' at Print(ID (a), id (b), ID (c))#memory addresses are the same -D=Copy.deepcopy (a) - Print(ID (a), id (b), ID (c))#C memory address is not the same, this is the deep copy -  - #Ternary Operations -A=8 inb=2 -C=bifB>aElseA#This is the ternary operation . to Print(c) +  - #format pass -through dictionary the Print('{name},{age}'. Format (age=18,name='XG')) *dic={' Age': 18,'name':'XG'} $ Print('{name},{age}'. Format_map (DIC))#Format_map This method behind a dictionary can bePanax Notoginseng #The result of the above output is the same

Python3 from zero single row _ Some fun stuff

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.