Computer Science

Consider the statements given below and then choose the correct output from the given options:

pride = "#G20 Presidency"
print(pride[-2:2:-2])
  1. ndsr
  2. ceieP0
  3. ceieP
  4. yndsr

Python String Manipulation

1 Like

Answer

ceieP0

Reason — The code assigns the string "#G20 Presidency" to the variable pride. The slicing operation pride[-2:2:-2] starts from the second last character ("y"), which is at index -2, moves backward by 2 characters at a time due to the step value of -2, and stops before reaching the third character ("G"), which is at index 2. Hence, the output will be 'ceieP0'.

Answered By

1 Like


Related Questions