Python 3 course strings

Hello, I am currently doing this course:
https://www.codecademy.com/courses/learn-python-3/lessons/python-functions-strings-cc/exercises/substring-between-letters

current code i wrote is:

def substring_between_letters(word, start, end):

    first_time_start = word.find(start)

    first_time_end = word.find(end)

    if first_time_start or first_time_end == -1:

        return word

    else:

        return word[first_time_start +1:first_time_end]


print(substring_between_letters("apple", "p", "e"))

print(substring_between_letters("apple", "p", "c"))

both return “apple” and after using vscode to run it I saw that the if statement is True even though first_time_start = 1 and first_time_end = 4, why is that? am I missing something?

Thanks

Edit: I figured out I am just an idiot and forgot how to use the or operator

For future reference, if you’re doing several things in a line, then you can split that up into smaller parts and observe them individually one operation at a time.

1 Like