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?

  1. A.

    print("AMARDEEP"[3::-1])

  2. B.

    print("AMARDEEP"[4::-1])

  3. C.

    print("AMARDEEP"[2::-1])

  4. 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'.

Explore the full course: Rssb Senior Computer Instructor