Which of the following print statements will display output as RAMA in Python?
2026
Which of the following print statements will display output as RAMA in Python?
- A.
print("AMARDEEP"[3::-1])
- B.
print("AMARDEEP"[4::-1])
- C.
print("AMARDEEP"[2::-1])
- D.
print("AMARDEEP"[3:-1])
Attempted by 111 students.
Show answer & explanation
Correct answer: A
To display 'RAMA' from the string 'AMARDEEP', use Python slicing. The character 'R' is at index 3. Slicing with [3::-1] starts at index 3 and steps backwards to the beginning of the string. This extracts characters at indices 3, 2, 1, and 0 ('R', 'A', 'M', 'A'), resulting in the output 'RAMA'.