python 字符串居中

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

 

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

result:code

1                   Now I am here.                  
2                                     Now I am here.
3 Now I am here.                                    
相关文章
相关标签/搜索