早上好,
我一直在嘗試消除句點與 sum(random_list) 輸出 [23739] 生成的數字之間的空間。但似乎無法弄清楚如何不將整個字串變成 f 字串。我知道添加逗號會自動插入一個空格,但是如果有更簡單的方法,誰能告訴我?謝謝!
下圖是我的作品;
截屏
uj5u.com熱心網友回復:
您可以使用format字串的功能。
print("The sum of the elements in random list is {}.".format(sum(random_list)))
uj5u.com熱心網友回復:
我認為這個 f-string 應該可以作業
print(f"The sum of the elements in random list is {sum(random_list)}.")
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/475040.html
標籤:Python python-3.x 细绳 列表
上一篇:如何注釋回傳其引數的函式
