InterviewSolution
Saved Bookmarks
| 1. |
5. What will be the output of the following code snippet ? Tup1 = ((1, 2),) * 7print(len(Tup1 (3:8])) |
|
Answer» 4Explanation:Line 1 INDICATES that the tuple within the tuple will be 7 times written within.So, the line STORES ((1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2), (1, 2)) in Tup1.The indexing STARTS from 0. As the Tup1 contains 7 elements, the indexing will be 0 to 6.(You have GIVEN Tup1(3:8]; it should be Tup1[3:8] as per slicing syntax)On slicing, Tup1[3:8] gives ((1, 2), (1, 2), (1, 2), (1, 2)) from 0 to outer bound 6 (as the range mentioned is upto 8)so, print(len(Tup1 [3:8])) gives 4 (as ((1, 2), (1, 2), (1, 2), (1, 2)) tuple contains 4 elements) |
|