The alignment of the string at output:
S.ljust (Width,[fillchar])
#输出width个字符, S left-aligned, insufficient parts are filled with Fillchar, the default is a space.
S.rjust (Width,[fillchar]) #右对齐
S.center (width, [Fillchar]) #中间对齐
S.zfill (width) #把S变成width长, and right-aligned, less part with 0 complement
Instance
1>>> str ="This is a string EXAMPLE....WOW!!!";2>>> Str.ljust (50,'0')3 'This is a string EXAMPLE....WOW!!! 000000000000000000'4>>> Str.ljust (50)5 'This is a string EXAMPLE....WOW!!! '6>>> Str.rjust (50)7 'This is a string EXAMPLE....WOW!!!'8>>> Str.rjust (50,'0')9 '000000000000000000this is string example....wow!!!'Ten>>> Str.center (50,'0') One '000000000this is string EXAMPLE....WOW!!! 000000000' A>>> Str.center (50) - 'This is a string EXAMPLE....WOW!!! ' ->>> Str.zfill (50) the '000000000000000000this is string example....wow!!!' ->>>
How to use Python ljust,rjust,center,zfill alignment