python 字符串居中

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

 

1 string1 = "Now I am here."
2 print( string1.center(50))
3 print( string1.rjust(50))
4 print (string1.ljust(50))

result:

1                   Now I am here.                  
2                                     Now I am here.
3 Now I am here.                                    

 

posted @ 2018-07-22 16:05  Niuli'blog  阅读(11426)  评论(0编辑  收藏  举报