f 字符串是否将整数转换为字符串?

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

你好,我正在练习使用循环,我发现在使用连接时我必须将 int 转换为字符串,但后来我发现如果我使用 f 字符串,我不需要将其转换为 int。


这是代码:

# some code up there

average_cost = [total_cost / len(actual_insurance_costs)]

# using a f-string
print(f"Average Insurance Cost: {average_cost} dollars.")

# using concatenation
print("Average Insurance Cost: " + str(average_cost) + " dollars.")

f-string 是否将 int 转换为字符串?

string list concatenation f-string python-3.12
1个回答
0
投票

是的,确实如此(通过调用

format
来实现)。

© www.soinside.com 2019 - 2024. All rights reserved.