掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流
python中使用format()方法格式化數(shù)字設置右對齊:< (默認)左對齊、> 右對齊、^ 中間對齊、= (只用于數(shù)字)在小數(shù)點后進行補齊

>>> 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位小數(shù)
1.123 is 1.12
>>> print('{0} is {0:>10.2f}'.format(1.123)) # 取2位小數(shù),右對齊,取10位
1.123 is 1.12
網(wǎng)站欄目:創(chuàng)新互聯(lián)Python教程:python怎么讓數(shù)字右對齊?
URL地址:http://uogjgqi.cn/article/dhjpdgd.html

我們在微信上24小時期待你的聲音
解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流