为了账号安全,请及时绑定邮箱和手机立即绑定

清理打印命令

清理打印命令

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 关注
  • 153 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号