Is there an easy way to set the default float presentation for Python's format command:
"{:5.3e}".format(a)
so that if the variable a has a value of None instead of a float, some default like 5 spaces might be printed?
The format string can be include many fields and is given by a user. The values in a are calculated internally.
答案 0 :(得分:0)
我会建议像
这样的东西print("{:.3e}".format(a)) if a else print(" "*5).
您不需要5.3e
,因为在科学记数法中,由于.3e,您总是得到5位数。除非您想将整个文本向右移动。然后你可以使用{:>10.3e}
。