Python Quest

Track 7 · Lesson 4 of 11

Searching inside text

Locate and count text with in, find, rfind, index and count, and check beginnings and endings with startswith and endswith.

About 35 minBeginner4 exercises

You will be able to

  • Choose between in, find() and index() depending on whether you need a yes/no answer or a position
  • Handle the 'not found' case correctly: -1 from find() and ValueError from index()
  • Count occurrences of a substring and search case-insensitively
  • Check how text starts or ends with startswith() and endswith(), including several options at once

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.