Test Index
Python Revision Tour
© examsnet.com
Question : 101 of 102
Marks:
+1,
-0
(a) Given is a Python string declaration : (1)
NAME = "Learning Python is Fun"Write the output of :
print(NAME[-5:-10:-1])(b) Write the output of the code given below : (1)dict1={1:["Rohit",20], 2:["Siya",90]}dict2={1:["Rahul",95], 5:["Rajan",80]}dict1.update(dict2)print(dict1.values())[CBSE 2023 Compartment]
Solution:
(a)Indexes of
Output:
NAME = "Learning Python is Fun" (length 22): the positive index of -5 is 22 - 5 = 17 and of -10 is 22 - 10 = 12.NAME[-5:-10:-1] = NAME[17:12:-1] takes indexes 17, 16, 15, 14, 13 (step -1, stop 12 not included):| Index | 17 | 16 | 15 | 14 | 13 |
| Character | s | i | (space) | n | o |
si no(b)
update() copies every pair of dict2 into dict1: the existing key 1 gets the new value ['Rahul', 95], and the new key 5 is added at the end. So dict1 = {1: ['Rahul', 95], 2: ['Siya', 90], 5: ['Rajan', 80]}.values() returns a view of the values in order.Output:dict_values([['Rahul', 95], ['Siya', 90], ['Rajan', 80]])
© examsnet.com
Go to Question: