Python 中列表形式的科学记数法

问题描述 投票:0回答:1

我有一个清单

A
。我想将此列表的元素转换为科学记数法。我介绍当前和预期的输出。

A = [0.000129,0.000148]
A_scientific = [f'{num:.2e}' for num in A]
print(A_scientific)

当前输出为

['1.29e-04', '1.48e-04']

预期输出是

[1.29e-04, 1.48e-04]
python list scientific-notation
1个回答
0
投票

您可以在 f 字符串中使用 str.join(),如下所示:

A = [0.000129,0.000148]
A_scientific = [f'{num:.2e}' for num in A]
print(f"[{', '.join(A_scientific)}]")

输出:

[1.29e-04, 1.48e-04]
© www.soinside.com 2019 - 2024. All rights reserved.