Skip to content

Question 4

Evaluate:

'lion'[1] + 'witch'[2:3] + 'wardrobe'[4:]
Hint

Evaluate each substring value in the expression.

Key:

  • 'string'[val] produces the character in index val from 'string'.
  • 'string'[start:stop:step]: start from the character at index start, stop before the character at index stop, and include characters in accordance to the step value (1 by default)
Solution
'lion'[1] + 'witch'[2:3] + 'wardrobe'[4:]
= 'i' + 't' + 'robe'
= 'itrobe'
Answer
'itrobe'