我有此列表:
list = [
0.6490486257928119,
0.2996742671009772,
0.589242053789731
]
我想将其转换为带有一个小数的百分比列表,如下所示:
list = [
64.9%,
29.9%,
58.9%
]
I don't know how to proceed.
type
从float
更改为str
。作为旁注:您不应使用list
作为变量名,因为那样的话,您将覆盖Pythons list
方法。
lst = [0.6490486257928119, 0.2996742671009772, 0.589242053789731]
new_lst = [f'{i*100:.1f}%' for i in lst]
print(new_lst)
list = [0.6490486257928119, 0.2996742671009772, 0.589242053789731]
new_list = [ round(x*100,1) for x in list] #each value in list multiplied by 100 and round up to 1 floating number
new_list = [64.9, 29.9, 58.9]
如果您想拥有%,可以转换为字符串
new_list = [ str(round(x*100,1))+"%" for x in list] new_list = ["64.9%", "29.9%", "58.9%"]
print("{0:.1f}%".format(0.6490486257928119*100))