Latest web development tutorials

Metodo Python endswith ()

stringhe Python stringhe Python


descrizione

Metodo Python endswith () viene utilizzato per determinare se una stringa termina con il suffisso specificato, se terminano con il suffisso specificato restituisce True, altrimenti False. Parametri opzionali "Start" e "End" per la posizione di inizio e fine della stringa di ricerca.

grammatica

endswith () metodo di sintassi:

str.endswith(suffix[, start[, end]])

parametri

  • suffisso - Il parametro può essere una stringa o un elemento.
  • iniziare - la posizione iniziale della stringa.
  • end - la posizione fine dei caratteri.

Valore di ritorno

Se la stringa contiene il suffisso specificato restituisce vera, altrimenti False.

Esempi

L'esempio seguente mostra il metodo endswith () esempio:

#!/usr/bin/python

str = "this is string example....wow!!!";

suffix = "wow!!!";
print str.endswith(suffix);
print str.endswith(suffix,20);

suffix = "is";
print str.endswith(suffix, 2, 4);
print str.endswith(suffix, 2, 6);

Esempi dei risultati di output di cui sopra sono i seguenti:

True
True
True
False

stringhe Python stringhe Python