[英]Cleaning up print command
我正在使用以下代碼行:
fwhost1 = "172.16.17.1"
print("Connecting via API call, backing up the configuration for:", fwhost1)
該行的輸出為:
('Connecting via API call, backing up the configuration for:', '172.16.17.1')
我正在尋找沒有括號,並且在腳本運行時在輸出上顯示單引號。
謝謝
我已經嘗試過調整代碼行,但這是它將運行且沒有錯誤的唯一方法
您可以使用+
運算符來連接字符串。 更多信息在這里
fwhost1 = "172.16.17.1"
print("Connecting via API call, backing up the configuration for: " + fwhost1)
這是使用%格式進行打印的另一種方式
print("Connecting via API call, backing up the configuration for: %s" % fwhost1)
另一種選擇是使用str.format()
print("Connecting via API call, backing up the configuration for: {}".format(fwhost1))
如果您使用的是Python 3,則可以使用f字符串
print(f"Connecting via API call, backing up the configuration for: {fwhost1}")
輸出量
通過API調用進行連接,備份以下配置:172.16.17.1
一種更pythonic的方法是在字符串上使用format
函數
fwhost1 = "172.16.17.1"
print ("Connecting via API call, backing up the configuration for:{}".format(fwhost1))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.