Find the Word Index
Hi there, it should be mentioned that there is another function that does the same action as find()
, which is called index()
.
Like the very similar function find()
, it finds the first appearance of the word. Look at the example to clarify its usage:
9
1
2
3
4
5
6
7
string = "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)
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)
As you may have recognized, the index()
function has the following syntax:
python912string.index('word')
Aufgabe
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
.
Lösung
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string = "It is cool to have a burning desire for studying"
# Find the index of "burning" word
burning = string.index('burning')
# Find the index of "desire" word
desire = string.index("desire")
# Find the index of "studying" word
studying = string.index("studying")
print("The index of the word burning is:", burning)
print("The index of the word desire is:", desire)
print("The index of the word studying is:", studying)
War alles klar?
Danke für Ihr Feedback!
Abschnitt 3. Kapitel 10
single
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
string = "It is cool to have a burning desire for studying"
# Find the index of "burning" word
burning = ___.index('___')
# Find the index of "desire" word
desire = string.___(___)
# Find the index of "studying" word
studying = ___.___
print("The index of the word burning is:", burning)
print("The index of the word desire is:", desire)
print("The index of the word studying is:", studying)
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen