Class - 12 CBSE Computer Science Important Output Questions 2025
What will be the output of the following code snippet ?
message = "World Peace"
print(message[-2::-2])
Python String Manipulation
14 Likes
Answer
Output
ce lo
Explanation
The code
message[-2::-2]
starts from the second-last (-2) character of the string "World Peace", which is "c".It moves backwards in steps of 2 to select every second character going towards the start of the string.
The traversal goes as follows:
- Index -2: Character is "c".
- Index -4: Character is "e".
- Index -6: Character is a space (" ").
- Index -8: Character is "l".
- Index -10: Character is "o".
The output is "ce lo".
Answered By
8 Likes