Question: 5 Find the output of the following program:
check1 = ['Learn', 'Quiz', 'Practice', 'Contribute'] check2 = check1 check3 = check1[:] check2[0] = 'Code'check3[1] = 'Mcq' count = 0for c in (check1, check2, check3): if c[0] == 'Code': count += 1 if c[1] == 'Mcq': count += 10 print (count) |
(A) 4
(B) 5
(C) 11
(D) 12
Answer: (D)
Explanation: When assigning check1 to check2, we create a second reference to the same list. Changes to check2 affect check1. When assigning the slice of all elements in check1 to check3, we are creating a full copy of check1 which can be modified independently (i.e, any change in check3 will not affect check1).
So, while checking check1 ‘Code’ gets matched and the count increases to 1, but Mcq doest gets matched since its available only in check3.
Now checking check2 here also ‘Code’ gets matched resulting in a count value to 2.
Finally while checking check3 which is separate from both check1 and check2 here only Mcq gets matched and the count becomes 12.
Quiz of this Question
Recommended Posts:
- Python-Quizzes | Python List Quiz | Question 13
- Python-Quizzes | Python List Quiz | Question 2
- Python-Quizzes | Python List Quiz | Question 22
- Python-Quizzes | Python List Quiz | Question 3
- Python-Quizzes | Python List Quiz | Question 4
- Python-Quizzes | Python List Quiz | Question 6
- Python-Quizzes | Python List Quiz | Question 7
- Python-Quizzes | Python List Quiz | Question 8
- Python-Quizzes | Python List Quiz | Question 9
- Python-Quizzes | Python List Quiz | Question 10
- Python-Quizzes | Python List Quiz | Question 11
- Python-Quizzes | Python List Quiz | Question 12
- Python-Quizzes | Python List Quiz | Question 14
- Python-Quizzes | Python List Quiz | Question 15
- Python-Quizzes | Python List Quiz | Question 16
- Python-Quizzes | Python List Quiz | Question 17
- Python-Quizzes | Python List Quiz | Question 18
- Python-Quizzes | Python List Quiz | Question 19
- Python-Quizzes | Python List Quiz | Question 20
- Python-Quizzes | Python List Quiz | Question 21

