亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

清理打印命令

清理打印命令

Cats萌萌 2021-12-29 18:31:48
我正在使用這行代碼: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')我希望在腳本運行時沒有括號和單引號出現在輸出中。謝謝我試過調整代碼行,但這是它運行沒有錯誤的唯一方法
查看完整描述

2 回答

?
呼如林

TA貢獻1798條經驗 獲得超3個贊

您可以使用+運算符連接字符串。更多信息在這里


fwhost1 = "172.16.17.1" 

print("Connecting via API call, backing up the configuration for: " + fwhost1)

這是使用 %-formatting 打印的另一種方式


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-strings


print(f"Connecting via API call, backing up the configuration for: {fwhost1}")

輸出


通過API調用連接,備份配置為:172.16.17.1


查看完整回答
反對 回復 2021-12-29
?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

一種更 Pythonic 的方法是format在字符串上使用函數


fwhost1 = "172.16.17.1"

print ("Connecting via API call, backing up the configuration for:{}".format(fwhost1))


查看完整回答
反對 回復 2021-12-29
  • 2 回答
  • 0 關注
  • 177 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號