Python Learning Note--coursera

Source: Internet
Author: User

Someting about Lists mutation

1 ###################################2 #Mutation vs. Assignment3 4 5 ################6 #Look alike, but different7 8A = [4, 5, 6]9b = [4, 5, 6]Ten Print "Original A and B:", A, b One Print "is they same thing?"+ F isb A  -A[1] = 20 - Print "New A and B:", A, b the Print -  - ################ - #aliased +  -c = [4, 5, 6] +D =C A Print "Original C and D:", C, D at Print "is they same thing?"+ D isD -  -C[1] = 20 - Print "New C and D:", C, D - Print -  in ################ - #Copied to  +e = [4, 5, 6] -f =list (e) the Print "Original E and F:", E, F * Print "is they same thing?"E isF $ Panax NotoginsengE[1] = 20 - Print "New E and F:", E, F the Print +  A  the ################################### + #Interaction with Globals -  $  $A = [4, 5, 6] -  - defMutate_part (x):#Note: The A defaults to global theA[1] =x - Wuyi defassign_whole (x): theA =x -  Wu defAssign_whole_global (x): -     Globala AboutA =x $  -Mutate_part (100) - Printa -  AAssign_whole (200) + Printa the  -Assign_whole_global (300) $ PrintA

Here the assignment needs to be noted:

b = A, then A, B points to the same piece of memory, to a[1] or b[1] assignment, can change the list;

b = List (a), then A, B points to different memory.

Global vs Local

Mutate_part (x) This function changes the a[1], where a is defaulted to global;

A in Assign_whole (x) is local.

Assign_whole_global (x) wants to make changes to global variables, so add the Global keyword

Lists & Tuples (multi-group)

difference: Lists is mutable; Tuples is immutable, strings is the same as tuples, immutable.

Python Learning Note--coursera

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.