Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Searching a String | Strings
Python Data Types
course content

Contenido del Curso

Python Data Types

Python Data Types

1. Numeric Types
2. Boolean Type
3. Strings

bookSearching a String

We also have the ability to search for substrings in strings using find() method. This method returns the index of the first occurrence of the substring. If there are no lines, then the function will return -1.

1234
string = 'Jackfruit, Coconut' position_1 = string.find('C') position_2 = string.find('c') print(f'The position of "C" is {position_1}, and the position of "c" is {position_2}')
copy

Don't forget Python is case sensitive. So, the first occurrence of the C is 11, and the first occurrence of the c is 2. Since C it is not the same as c.

Tarea

Swipe to show code editor

test

You have such a string

string = "apple, banana, cherry, orange"

You have to find out the index of the first occurence of such substrings as:

a, h, y, Y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 10
toggle bottom row

bookSearching a String

We also have the ability to search for substrings in strings using find() method. This method returns the index of the first occurrence of the substring. If there are no lines, then the function will return -1.

1234
string = 'Jackfruit, Coconut' position_1 = string.find('C') position_2 = string.find('c') print(f'The position of "C" is {position_1}, and the position of "c" is {position_2}')
copy

Don't forget Python is case sensitive. So, the first occurrence of the C is 11, and the first occurrence of the c is 2. Since C it is not the same as c.

Tarea

Swipe to show code editor

test

You have such a string

string = "apple, banana, cherry, orange"

You have to find out the index of the first occurence of such substrings as:

a, h, y, Y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 3. Capítulo 10
toggle bottom row

bookSearching a String

We also have the ability to search for substrings in strings using find() method. This method returns the index of the first occurrence of the substring. If there are no lines, then the function will return -1.

1234
string = 'Jackfruit, Coconut' position_1 = string.find('C') position_2 = string.find('c') print(f'The position of "C" is {position_1}, and the position of "c" is {position_2}')
copy

Don't forget Python is case sensitive. So, the first occurrence of the C is 11, and the first occurrence of the c is 2. Since C it is not the same as c.

Tarea

Swipe to show code editor

test

You have such a string

string = "apple, banana, cherry, orange"

You have to find out the index of the first occurence of such substrings as:

a, h, y, Y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

We also have the ability to search for substrings in strings using find() method. This method returns the index of the first occurrence of the substring. If there are no lines, then the function will return -1.

1234
string = 'Jackfruit, Coconut' position_1 = string.find('C') position_2 = string.find('c') print(f'The position of "C" is {position_1}, and the position of "c" is {position_2}')
copy

Don't forget Python is case sensitive. So, the first occurrence of the C is 11, and the first occurrence of the c is 2. Since C it is not the same as c.

Tarea

Swipe to show code editor

test

You have such a string

string = "apple, banana, cherry, orange"

You have to find out the index of the first occurence of such substrings as:

a, h, y, Y.

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 3. Capítulo 10
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
some-alt