欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

簡(jiǎn)介Python中用于處理字符串的center()方法

 更新時(shí)間:2015年05月18日 09:48:22   投稿:goldensun  
這篇文章主要介紹了簡(jiǎn)介Python中用于處理字符串的center()方法,是Python入門(mén)中的基礎(chǔ)知識(shí),需要的朋友可以參考下

 center()方法返回集中在長(zhǎng)度寬度的字符串。填充是通過(guò)使用specifiedfillchar。默認(rèn)填充字符是一個(gè)空格。
語(yǔ)法

以下是center()方法的語(yǔ)法:

str.center(width[, fillchar])

參數(shù)

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

返回值

此方法返回集中在長(zhǎng)度寬度的字符串。
例子

下面的示例演示center()方法的使用。

#!/usr/bin/python

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

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

當(dāng)我們運(yùn)行上面的程序,它會(huì)產(chǎn)生以下結(jié)果:

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

相關(guān)文章

最新評(píng)論