69pao国产精品视频-久久精品一区二区二三区-精品国产精品亚洲一本大道-99国产综合一区久久

Python center()方法

Python center()方法

Python 字符串Python 字符串

Python center() 返回一個(gè)原字符串居中,并使用空格填充至長(zhǎng)度 width 的新字符串。默認(rèn)填充字符為空格。

 

語(yǔ)法

center()方法語(yǔ)法:

str.center(width[, fillchar])

 

參數(shù)

  • width -- 字符串的總寬度。
  • fillchar -- 填充字符。

 

返回值

該方法返回一個(gè)原字符串居中,并使用空格填充至長(zhǎng)度 width 的新字符串。

 

實(shí)例

以下實(shí)例展示了center()方法的實(shí)例:

>>>str = 'codebaoku'
>>> str.center(20, '*')
'*****codebaoku******'
>>> str.center(20)
'     codebaoku      '
>>>

Python 字符串Python 字符串

下一節(jié):Python decode()方法

Python 教程

相關(guān)文章