Section 3. Chapter 10
single
Find the Word Index
Swipe to show menu
Hi there, it should be mentioned that there is another function that does the same action as find(), which is called index().
Like find(), it returns the index of the first occurrence of a substring:
1234567string = "I can manage everything" manage = string.index('manage') everything = string.index('everything') print("The index of the word manage is", manage) print("The index of the word everything is", everything)
The index() function has the following syntax:
string.index('word')
Definition
The index() function returns the first occurrence of the word in the string, and the valuable point is that it throws an exception if the word is not found.
Task
Swipe to start coding
Here's one more simple task to increase your knowledge base.
- Find the index of the word
burning. - Find the index of the word
desire. - Find the index of the word
studying.
Solution
Everything was clear?
Thanks for your feedback!
Section 3. Chapter 10
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat