Good job! Next, we have two similar functions,
text = ('In this course, we will learn a lot of things related to Python.'
'It is an amazing modern programming language that we highly recommend.'
'We are going to cover variables, loops, conditional statements and lists.')
find('loops') search for the
'loops' string in the
text variable. If found, both of them return the index of the first occurrence of
'loops'. The code above will print the
167 index twice.
When the substring is not found in the text, there is a subtle difference between these two functions:
index() raises a
If you'd like to learn how to handle exceptions in Python, take a look at Python Basics Part 2.