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

Swipe um das Menü anzuzeigen

book
Get the Index of the Symbol

To find the index of a specific symbol or substring in a string, Python provides the built-in .find() method. This method returns the index of the first occurrence of the substring. If the substring is not found, it returns -1.

python

Here, string is the original text, and substring is the character or sequence you want to locate.

12
string = "Channel efforts to success!" print(string.find('n'))
copy

In the string "Channel efforts to success!", the first 'n' appears at index 2. So, the find() method returns 2.

If the character were not found, for example, string.find('z'), the result would be -1.

Aufgabe

Swipe to start coding

Hone your skills as much as possible!

So here you should find the index of the letters p, y, and r.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 3. Kapitel 9
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

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

close

Awesome!

Completion rate improved to 3.03

book
Get the Index of the Symbol

To find the index of a specific symbol or substring in a string, Python provides the built-in .find() method. This method returns the index of the first occurrence of the substring. If the substring is not found, it returns -1.

python

Here, string is the original text, and substring is the character or sequence you want to locate.

12
string = "Channel efforts to success!" print(string.find('n'))
copy

In the string "Channel efforts to success!", the first 'n' appears at index 2. So, the find() method returns 2.

If the character were not found, for example, string.find('z'), the result would be -1.

Aufgabe

Swipe to start coding

Hone your skills as much as possible!

So here you should find the index of the letters p, y, and r.

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

close

Awesome!

Completion rate improved to 3.03

Swipe um das Menü anzuzeigen

some-alt