Last active 9 months ago

Python 提供多種字串格式化方法,f-string(Python 3.6+)更直觀且效能較佳,而 str.format() 適用於較舊版本。這些方法常用於動態組合字串,如建立 URL、日誌輸出或命令構造。

timmy revised this gist 9 months ago. Go to revision

1 file changed, 3 insertions

string_formatting.py(file created)

@@ -0,0 +1,3 @@
1 + url = f"http://localhost:{args.port}"
2 +
3 + url = "http://localhost:{}".format(args.port)
Newer Older