Metodo Python String expandtabs ()

Descrizione

Metodo delle stringhe Python expandtabs()restituisce una copia della stringa in cui i caratteri di tabulazione es. "\ t" vengono espansi utilizzando spazi, opzionalmente utilizzando la dimensione di tabulazione data (impostazione predefinita 8).

Sintassi

str.expandtabs(tabsize=8)

Parametri

  • tabsize - Specifica il numero di caratteri da sostituire per un carattere di tabulazione "\ t".

  • Valore di ritorno

  • Questo metodo restituisce una copia della stringa in cui i caratteri di tabulazione, ad esempio "\ t", sono stati espansi utilizzando spazi.

Esempio

#!/usr/bin/python

str = "this is\tstring example....wow!!!";

print "Original string: " + str
print "Defualt exapanded tab: " +  str.expandtabs()
print "Double exapanded tab: " +  str.expandtabs(16)

Risultato

Original string: this is        string example....wow!!!
Defualt exapanded tab: this is string example....wow!!!
Double exapanded tab: this is         string example....wow!!!