Consider the following statement:
Country = pd.Series(['India','Nepal','Germany','Poland','USA'])
What will the following command result in?
print (Country [: : -1])
Consider the following statement:
Country = pd.Series(['India','Nepal','Germany','Poland','USA'])
What will the following command result in?
print (Country [: : -1])
Solution
The slice [::-1] uses a step of -1, so it reads the Series from the last element to the first. The elements come out in reverse order, and each keeps its original index label. The output is therefore USA (4), Poland (3), Germany (2), Nepal (1), India (0), with dtype object.
| Position read | Index label | Value |
|---|---|---|
| 1st | 4 | USA |
| 2nd | 3 | Poland |
| 3rd | 2 | Germany |
| 4th | 1 | Nepal |
| 5th | 0 | India |
Option 1: the values are reversed, but the index is wrongly renumbered from 0 and India is missing.
Option 2: this is the original Series, which [::] or [:] would print.
Option 4: it drops USA and shows the original labels attached to the wrong values.
Slicing a Series reverses the order but never resets the index labels; use reset_index(drop=True) if you want fresh labels.
Related questions:
2026: 11 May Shift 2
2025: 20 May Shift 1