Python输出当中的占位符以及保留小数位数

百分号前面的数字表示输出数字前面的空格数,后面的“.x”表示保留小数为x位小数,就这么简单!但是需要记住!如下面的代码所示:

>>> print("my age is %8.3f"%(18.89898))
my age is           18.899
>>> print("my age is %20.3f"%(18.89898))
my age is                         18.899

posted @ 2020-02-29 13:47  Geeksongs  阅读(2678)  评论(0编辑  收藏  举报

Coded by Geeksongs on Linux

All rights reserved, no one is allowed to pirate or use the document for other purposes.