Test Index

CBSE Class 12 Computer Science 2026 Paper Set 4 Get it on Google PlayDownload on the App Store

© examsnet.com
Question : 5 of 37
Marks: +1, -0
What will be the output of the following statement ?
print("PythonProgram"[-1:2:-2])
Solution:  
Concept:
In a slice s[start:stop:step] with a negative step, Python starts at start, moves to the left by |step| each time and stops before reaching index stop.
Explanation:
"PythonProgram" has 13 characters, indices 0 to 12:
index : 0 1 2 3 4 5 6 7 8 9 10 11 12
char : P y t h o n P r o g r a m
start = -1 → index 12, step = -2, stop = 2 (excluded).
Indices taken: 12, 10, 8, 6, 4 (the next one, 2, is the stop and is not included).
Characters: s[12] = 'm', s[10] = 'r', s[8] = 'o', s[6] = 'P', s[4] = 'o'
Output:
mroPo
© examsnet.com
Advertisements
Go to Question: