Metodo Python String find ()

Descrizione

Metodo delle stringhe Python find()determina se string str si trova in string, o in una sottostringa di string se sono dati inizio indice beg e fine indice finale .

Sintassi

str.find(str, beg=0, end=len(string))

Parametri

  • str - Specifica la stringa da cercare.

  • beg - Questo è l'indice iniziale, per impostazione predefinita è 0.

  • end - Questo è l'indice finale, per impostazione predefinita è uguale alla lunghezza della stringa.

Valore di ritorno

Indicizza se trovato e -1 altrimenti.

Esempio

#!/usr/bin/python

str1 = "this is string example....wow!!!";
str2 = "exam";

print str1.find(str2)
print str1.find(str2, 10)
print str1.find(str2, 40)

Risultato

15
15
-1