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

Python中字符串對齊方法介紹

 更新時間:2015年05月21日 09:44:17   投稿:junjie  
這篇文章主要介紹了Python中字符串對齊方法介紹,本文介紹Python字符串內(nèi)置方法ljust、rjust、center的用法,需要的朋友可以參考下

目的

  實現(xiàn)字符串的左對齊,右對齊,居中對齊。

方法

  字符串內(nèi)置了以下方法:其中width是指包含字符串S在內(nèi)的寬度,fillchar默認是空格,也可以指定填充字符

復(fù)制代碼 代碼如下:

string.ljust(s, width[, fillchar])
string.rjust(s, width[, fillchar])
string.center(s, width[, fillchar])

復(fù)制代碼 代碼如下:

In [6]: a='Hello!'

In [7]: print a.ljust(10,'+')
Hello!++++

In [8]: print a.rjust(10,'+')
++++Hello!

In [9]: print a.center(10,'+')
++Hello!++

相關(guān)文章

最新評論