且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用format()对齐并打印浮动列表

更新时间:2023-12-05 17:45:58

你可以用对齐的格式添加。#f

You can just add the .#f in the format with the alignment.

with open('format_test.dat', "a") as f_out:
    f_out.write('''{:>10.2f} {:>15.4f} {:>16.5f} {:>15.3f}'''.format(a, b, c, d))
    f_out.write('\n')