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.                                    
原文地址:https://www.cnblogs.com/niuli1987/p/9350461.html