Test Index

CBSE Class 12 Computer Science 2025 Paper Compartment 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 code segment ?
p=list("Session 2024-25")
print(p[10:20:])
Solution:  
Concept:
list(string) makes a list of the single characters of the string. A slice p[start:stop] takes the elements from index start up to stop - 1; a stop beyond the end simply stops at the last element (no error).
Explanation:
"Session 2024-25" has 15 characters (indexes 0 to 14):
S→0, e→1, s→2, s→3, i→4, o→5, n→6, space→7, 2→8, 0→9, 2→10, 4→11, -→12, 2→13, 5→14
p[10:20:] takes indexes 10 to 14 (index 20 does not exist, so the slice ends at 14).
Output:
['2', '4', '-', '2', '5']
© examsnet.com
Advertisements
Go to Question: