Latest web development tutorials

Metodo centro Python ()

Metodo centro Python ()

stringhe Python stringhe Python


descrizione

Centro Python () Restituisce una stringa del nucleo originario, e riempito con spazi per la nuova stringa di lunghezza larghezza. Il carattere di riempimento predefinito è lo spazio.

grammatica

Centro () metodo di sintassi:

str.center(width[, fillchar])

parametri

  • Larghezza - la larghezza totale della stringa.
  • fillchar - pieno di caratteri.

Valore di ritorno

Questo metodo restituisce un nucleo originario di stringa, e riempito con spazi per la nuova stringa di lunghezza larghezza.

Esempi

L'esempio seguente mostra il metodo di istanza centrale ():

#!/usr/bin/python

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

print "str.center(40, 'a') : ", str.center(40, 'a')

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

str.center(40, 'a') :  aaaathis is string example....wow!!!aaaa

stringhe Python stringhe Python