python怎么读的python右对齐输出数字怎么办_解决python让数字右对齐的⽅
解决python让数字右对齐的⽅法
发布时间:2020-07-03 15:42:31
来源:亿速云
阅读:121
作者:清晨
不懂解决python让数字右对齐的⽅法?其实想解决这个问题也不难,下⾯让⼩编带着⼤家⼀起学习怎么去解决,希望⼤家阅读完这篇⽂章后⼤所收获。
python中使⽤format()⽅法格式化数字设置右对齐:< (默认)左对齐、> 右对齐、^ 中间对齐、= (只⽤于数字)在⼩数点后进⾏补齐
>>> print('{} and {}'.format('hello','world'))  # 默认左对齐hello and world
>>> print('{:10s} and {:>10s}'.format('hello','world'))  # 取10位左对齐,取10位右对齐hello      and      world
>>> print('{:^10s} and {:^10s}'.format('hello','world'))  # 取10位中间对齐hello    and  world
>>> print('{} is {:.2f}'.format(1.123,1.123))  # 取2位⼩数1.123 is 1.12
>>> print('{0} is {0:>10.2f}'.format(1.123))  # 取2位⼩数,右对齐,取10位1.123 is      1.12
感谢你能够认真阅读完这篇⽂章,希望⼩编分享解决python让数字右对齐的⽅法内容对⼤家有帮助,同时也希望⼤家多多⽀持亿速云,关注亿速云⾏业资讯频道,遇到问题就亿速云,详细的解决⽅法等着你来学习!