center()方法返回集中在長度寬度的字符串。填充是通過使用specifiedfillchar。默認填充字符是一個空格。
語法
以下是center()方法的語法:
str.center(width[, fillchar])
參數
返回值
此方法返回集中在長度寬度的字符串。
例子
下面的示例演示center()方法的使用。
#!/usr/bin/pythonstr = "this is string example....wow!!!";print "str.center(40, 'a') : ", str.center(40, 'a')
當我們運行上面的程序,它會產生以下結果:
str.center(40, 'a') : aaaathis is string example....wow!!!aaaa
新聞熱點
疑難解答
圖片精選