Home  >  Article  >  Backend Development  >  python字符串对其居中显示的方法

python字符串对其居中显示的方法

WBOY
WBOYOriginal
2016-06-10 15:09:302364browse

本文实例讲述了python字符串对其居中显示的方法。分享给大家供大家参考。具体如下:

下面的代码可以让字符串居中,左对齐和右对齐,字符串长度设置为50,居中后左右补充空格,右对齐会在左侧补充空格

string1 = "Now I am here."
print string1.center( 50 )
print string1.rjust( 50 )
print string1.ljust( 50 )

希望本文所述对大家的Python程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn