清理打印命令

我正在使用这行代码:

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')

我希望在脚本运行时没有括号和单引号出现在输出中。

谢谢

我试过调整代码行,但这是它运行没有错误的唯一方法


Cats萌萌
浏览 154回答 2
2回答

呼如林

您可以使用+运算符连接字符串。更多信息在这里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-stringsprint(f"Connecting via API call, backing up the configuration for: {fwhost1}")输出通过API调用连接,备份配置为:172.16.17.1

慕的地10843

一种更 Pythonic 的方法是format在字符串上使用函数fwhost1 = "172.16.17.1"print ("Connecting via API call, backing up the configuration for:{}".format(fwhost1))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python