Python interview questions part 47

Python interview questions part 47

Take as many assements as you can to improve your validate your skill rating

Total Questions: 20

1. Which type of copy is shown in this code? l1=[[10, 20], [30, 40], [50, 60]] ls=list(l1) ls [[10, 20], [30, 40], [50, 60]]

Correct Answer is : Shallow copy

2. What is the output of the code shown below? l=[2, 3, [4, 5]] l2=l.copy() l2[0]=88 l l2

Correct Answer is : [2, 3, [4, 5]]

3. What is the output of the code shown below? l=[2, 3, [4, 5]] l2=l.copy() l2[0]=88 l l2

Correct Answer is : [2, 3, [4, 5]]

4. In _______________ copy, the base address of the objects are copied. In _______________ copy, the base address of the objects are not copied.

Correct Answer is : shallow, deep

5. In _______________ copy, the base address of the objects are copied. In _______________ copy, the base address of the objects are not copied.

Correct Answer is : shallow, deep

6. The nested list undergoes shallow copy even when the list as a whole undergoes deep copy. State whether this statement is true or false.

Correct Answer is : TRUE

7. The nested list undergoes shallow copy even when the list as a whole undergoes deep copy. State whether this statement is true or false.

Correct Answer is : TRUE

8. The output of the code shown below and state the type of copy that is depicted: l1=[2, 4, 6, 8] l2=[1, 2, 3] l1=l2 l2

Correct Answer is : [1, 2, 3], shallow copy

9. The output of the code shown below and state the type of copy that is depicted: l1=[2, 4, 6, 8] l2=[1, 2, 3] l1=l2 l2

Correct Answer is : [1, 2, 3], shallow copy

10. What is the output of the codes shown below? l1=[10, 20, 30] l2=l1 id(l1)==id(l2)   l2=l1.copy() id(l1)==id(l2)

Correct Answer is : True, False

11. What is the output of the codes shown below? l1=[10, 20, 30] l2=l1 id(l1)==id(l2)   l2=l1.copy() id(l1)==id(l2)

Correct Answer is : True, False

12. What is the output of the code shown below? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)

Correct Answer is : FALSE

13. What is the output of the code shown below? l1=[1, 2, 3, [4]] l2=list(l1) id(l1)==id(l2)

Correct Answer is : FALSE

14. What is the output of the code shown below? l1=[10, 20, 30, [40]] l2=copy.deepcopy(l1) l1[3][0]=90 l1 l2

Correct Answer is : [10, 20, 30 [90]]

15. What is the output of the code shown below? l1=[10, 20, 30, [40]] l2=copy.deepcopy(l1) l1[3][0]=90 l1 l2

Correct Answer is : [10, 20, 30 [90]]

16. Fill in the blanks: In ____________________ copy, the modification done on one list affects the other list. In ____________________ copy, the modification done on one list does not affect the other list.

Correct Answer is : shallow, deep

17. Fill in the blanks: In ____________________ copy, the modification done on one list affects the other list. In ____________________ copy, the modification done on one list does not affect the other list.

Correct Answer is : shallow, deep

18. What is the output of the code shown below? l1=[1, 2, 3, (4)] l2=l1.copy() l2 l1

Correct Answer is : [1, 2, 3, 4]

19. What is the output of the code shown below? l1=[1, 2, 3, (4)] l2=l1.copy() l2 l1

Correct Answer is : [1, 2, 3, 4]

20. What is the output of the piece of code given below? def check(n): if n < 2: return n % 2 == 0 return check(n - 2) print(check(11))

Correct Answer is : FALSE

Similar Interview Questions

    Search for latest jobs

    Icon
    Icon