1(xx)
What will be the output of the Python code given below?
x = "BOARD EXAMINATION" print(x[0:4:2])
- (a)BOAR
- (b)BA
- (c)OR
- (d)Error
Show SolutionHide Solution↓
BA
Reason — The string "BOARD EXAMINATION" is stored in variable x. Python uses 0-based indexing.
Index Table:
| Index | Character |
|---|---|
| 0 | B |
| 1 | O |
| 2 | A |
| 3 | R |
| 4 | D |
| 5 | (space) |
| 6 | E |
| 7 | X |
| 8 | A |
| 9 | M |
| 10 | I |
| 11 | N |
| 12 | A |
| 13 | T |
| 14 | I |
| 15 | O |
| 16 | N |
The slice x[0:4:2] means:
- Start from index 0
- Go up to index 4 (excluded)
- Take every 2nd character (step = 2)
So selected indices:
→ 0 → B
→ 2 → A
Thus, the output is BA.