Seriescntry = pd.Series(['India', 'Canada', 'Brazil', 'Australia', 'USA', China', 'Russia']) is created. If slicing is performed using Seriescntry = Seriescntry[3: 5], then what will be the output?
Seriescntry = pd.Series(['India', 'Canada', 'Brazil', 'Australia', 'USA', China', 'Russia']) is created. If slicing is performed using Seriescntry = Seriescntry[3: 5], then what will be the output?
Solution
✅ Correct Option: 1
Slicing a Series with [start:stop] uses position, starting from 0, and the stop position is excluded. So [3:5] returns positions 3 and 4.
| Position | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| Value | India | Canada | Brazil | Australia | USA | China | Russia |
The result keeps the original index labels:
3 Australia
4 USA
Option 2: includes position 5, but the stop value is excluded in positional slicing. Only .loc[3:5] with labels would include 5.
Options 3 and 4: start at position 2 (Brazil), but the slice starts at position 3.
Related questions:
2025: 14 May Shift 1
2026: 18 May Shift 2
2026: 31 May Shift 1