Skip to main contentSkip to solution

What will be output of the following python code?

import pandas as pd

series1 = pd.Series(["Kavi","Shyam","Ravi"], index=[3,5,1])

print(series1[::-1])

Solution

✅ Correct Option: 3

The slice [::-1] reverses the order of the Series. Each index label stays attached to its own value, so the pairs 3-Kavi, 5-Shyam and 1-Ravi are listed from last to first.

The output is:

1      Ravi
5     Shyam
3      Kavi
dtype: object

Option 2: it reverses the values but also moves the labels, giving wrong pairs such as 3-Shyam and 5-Kavi.

Option 4: it drops the index, but a Series always prints its index labels.

Slicing with [::-1] never changes the label-value pairs, only their order. Real pandas output also ends with the line dtype: object.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question