如何删除字符串中表达式和句点之间的 space? (Python 3)

How to remove space between expression and period within a string? (Python 3)

早上好,

我一直在尝试去除句点和 sum(random_list) 输出 [23739] 生成的数字之间的 space。但似乎无法弄清楚如何不将整个字符串转换为 f 字符串。我知道添加逗号会自动插入 space,但是谁能告诉我是否有更简单的方法?谢谢!

下图是我的作品;

Screen shot

我认为这个f-string应该可行

print(f"The sum of the elements in random list is {sum(random_list)}.")

您可以使用字符串的 format 功能。

print("The sum of the elements in random list is {}.".format(sum(random_list)))