python - 格式{:%}: Add space between digit and percentage

标签 python python-3.x format

是否可以从 python 替换字段获取此输出?

'{:.1%}'.format(0.4) # -> 40.0 %

我想在数字后面有一个空格。

我当前的解决方法是:

'{:.1f} %'.format(0.4 * 100)

最佳答案

作为doc说,当您使用 % 格式运算符时,

it multiplies the number by 100 and displays in fixed ('f') format, followed by a percent sign.

没有空间或无法添加。

所以你的解决方法就是解决方案

关于python - 格式{:%}: Add space between digit and percentage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37023871/

相关文章:

c# - 在 C# 中为 double 添加千位分隔符

JavaScript 格式数字始终为 3 位数字

python - 更改后使本地服务器重新加载代码

python-3.x - 如何定义可订阅的 `NewType`,例如 `List[int]`

python - SPSS 中如何确定数字和字符串变量?

python - 在字符串格式中调用类方法

python - OrderedDict 如何在 Python 中保持有序

python - 设置 cv2 窗口的全屏属性时出错

python - 如何在python和streamlit中下载excel文件?

python - 使用 ModelForm Django 时出现 ValidationError