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

TA貢獻1785條經驗 獲得超8個贊
一種更 Pythonic 的方法是format在字符串上使用函數
fwhost1 = "172.16.17.1"
print ("Connecting via API call, backing up the configuration for:{}".format(fwhost1))
添加回答
舉報