KnowledgeBoat Logo
|

Robotics & Artificial Intelligence

Give the output of the following Python code:

msg = "Artificial Intelligence"
print(msg[11:14])
  1. tel
  2. Int
  3. ell
  4. gen

Python String Manipulation

3 Likes

Answer

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:

IndexCharacter
0A
1r
2t
3i
4f
5i
6c
7i
8a
9l
10(space)
11I
12n
13t
14e
15l
16l
17i
18g
19e
20n
21c
22e

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.

Answered By

1 Like


Related Questions