Summary of Interview questions

Source: Internet
Author: User

1. Convert the value of A/b by one line
A=1b=2A, a =b,aprint(b)

Memory two things, one is 1 and 2 of the memory address, one is the namespace, the name space is the variable and the value of the corresponding relationship

The corresponding relation is the memory address that the variable points to, and the content is found through the memory address.

A,b=b,a changed the correspondence.

2. Type of judgment
u1 = (1= (1,)print(Tu1,type (TU1))print= ([1= ([1  ],)print(tu1,type (TU1))print(Tu2,type (TU2))

Tuples If there is only one element in the tuple and no commas, then what type is this element?

3. Go to the heavy
li=[1,2,33,33,2,1,4,5,6,6]set1=Set (LI)print(set1) li=list (set1 )print(LI)

4. Depth copy

1. Assignment operation

L1 = [1,2,3,['Barry','Alex']]l2=L1l1[0]= 111Print(L1)#[111, 2, 3, [' Barry ', ' Alex ']Print(L2)#[111, 2, 3, [' Barry ', ' Alex ']l1[3][0] ='Wusir'Print(L1)#[111, 2, 3, [' Wusir ', ' Alex ']Print(L2)#[111, 2, 3, [' Wusir ', ' Alex ']
Assign Value

For assignment operations, L1 and L2 point to the same memory address, so they are exactly the same

2. Shallow copy

L1 = [1,2,3,['Barry','Alex']]l2=l1.copy ()Print(L1,id (L1))#[1, 2, 3, [' Barry ', ' Alex ']] 2380296895816Print(L2,id (L2))#[1, 2, 3, [' Barry ', ' Alex ']] 2380296895048l1[1] = 222Print(L1,id (L1))#[1, 222, 3, [' Barry ', ' Alex ']] 2593038941128Print(L2,id (L2))#[1, 2, 3, [' Barry ', ' Alex ']] 2593038941896l1[3][0] ='Wusir'Print(L1,id (l1[3]))#[1, 2, 3, [' Wusir ', ' Alex ']] 1732315659016Print(L2,id (l2[3]))#[1, 2, 3, [' Wusir ', ' Alex ']] 1732315659016
Shallow Copy

In a shallow copy, the first layer creates a new memory address, and from the second level it points to the same memory address, so for the second and deeper layers, consistency is maintained.
List inside the list, the first layer points to the common memory, the second layer points to different memory

3. Deep copy

ImportCOPYL1= [1,2,3,['Barry','Alex']]l2=copy.deepcopy (L1)Print(L1,id (L1))#[1, 2, 3, [' Barry ', ' Alex ']] 2915377167816Print(L2,id (L2))#[1, 2, 3, [' Barry ', ' Alex ']] 2915377167048l1[1] = 222Print(L1,id (L1))#[1, 222, 3, [' Barry ', ' Alex ']] 2915377167816Print(L2,id (L2))#[1, 2, 3, [' Barry ', ' Alex ']] 2915377167048l1[3][0] ='Wusir'Print(L1,id (l1[3]))#[1, 222, 3, [' Wusir ', ' Alex ']] 2915377167240Print(L2,id (l2[3]))#[1, 2, 3, [' Barry ', ' Alex ']] 2915377167304
Deep Copy

Deep copy: List of nested tables, two points to different memory addresses
For deep copy, the two are completely independent, changing any element of any one (no matter how many layers), and the other absolutely does not change.

Summary of Interview questions

Related Article

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.