Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Find the Word Index | String Manipulation and Operations
Data Types in Python

book
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:

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)
1234567
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)
copy

As you may have recognized, the index() function has the following syntax:

python
string.index('word')

Aufgabe

Swipe to start coding

Here's one more simple task to increase your knowledge base.

  1. Find the index of the word burning.
  2. Find the index of the word desire.
  3. Find the index of the word studying.

Lösung

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?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 10
single

single

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

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt