FAQ: Code Challenge: String Methods - Substring Between


This community-built FAQ covers the “Substring Between” exercise from the lesson “Code Challenge: String Methods”.

Paths and Courses
This exercise can be found in the following Codecademy content:

FAQs on the exercise Substring Between

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


def substring_between_letters(word, start, end):
mystring = [word.find(start)-1:word.find(end)]:
return mystring
I think this should work but im getting a syntax error.


This worked just fine for me:

Write your substring_between_letters function here:

def substring_between_letters(word, start, end):
s = word.find(start) + 1
e = word.find(end)
if s < 0 or e < 0:
return word
return word[s:e]

Uncomment these function calls to test your tip function:

print(substring_between_letters(“apple”, “p”, “e”))

should print “pl”

print(substring_between_letters(“apple”, “p”, “c”))

should print “apple”


Curious why my code didn’t work. I must be missing something in the fun. Could not solve for ‘pl’

def substring_between_letters(word, start, end):
  if word.find(start) < 0 or word.find(end) < 0:
    return word


Why not just use:

You also forgot the return in your else.


def substring_between_letters(word,start,end):
the_list =
the_end_list =
for i in range(0,len(word)):
if(word [i] == start):
for j in range(len(word)-1,-1,-1):
if(word [j] == end):
return word[the_list[0]:the_list[-1]]
I get a warning that int object is not subscriptable. I am wondering Why cannot I acces my list in the function