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))
添加回答
举报