1(xviii)
Give the output of the following Python code:
msg = "Artificial Intelligence" print(msg[11:14])
- (a)tel
- (b)Int
- (c)ell
- (d)gen
Show SolutionHide Solution↓
Int
Reason — The given code stores the string "Artificial Intelligence" in the variable msg. Python follows 0-based indexing, where the first character is at index 0.
Index Table:
| Index | Character |
|---|---|
| 0 | A |
| 1 | r |
| 2 | t |
| 3 | i |
| 4 | f |
| 5 | i |
| 6 | c |
| 7 | i |
| 8 | a |
| 9 | l |
| 10 | (space) |
| 11 | I |
| 12 | n |
| 13 | t |
| 14 | e |
| 15 | l |
| 16 | l |
| 17 | i |
| 18 | g |
| 19 | e |
| 20 | n |
| 21 | c |
| 22 | e |
The statement msg[11:14] performs string slicing, where:
- 11 is the starting index (included)
- 14 is the ending index (excluded)
Thus, characters at index 11, 12, and 13 are selected: 'Int'.
Hence, the output is Int.