replit

Before you start this course, you must login to Replit

If you have forgotten your Replit account user name or password, ask your Coder Coach.

CoderSports


Investigate

The ‘investigate’ stage gives students some example code and asks them questions about it to check their understanding. I use the block model to plan my questions. Try it, it’s really useful.


Substrings

A substring returns a sequence of characters from a string. Python uses slices to do this.

Slices treat strings like lists. Each character is given an index number starting with 0.

[0,1,2,3,4,...]

The slice uses two indexes, the start character and the end character (NOTE the end character is NOT INCLUDED in the slice).

The slice indexes come in brackets after the string or the variable containing the string.

# Outputs 'ompu'
print("Computing"[1:5])

word = "dalmatian"

# Outputs 'ma'
print(word[3:5])

Help! My Code Does Not Work!

Make sure to check your code for the following things:

  • The start and end indices are surrounded by square brackets
  • The start and end indices have a colon : between them.
  • The end index is one more than the character you want to stop on.

Hints