希望你能帮我解决我在python中遇到的问题。 我正在尝试使用模板的字符串格式,但需要一些如何使用默认值。
template = """
Server {isServerRunning}
NTP {isNTPrunning}
Application {isAppRunning}
"""
test = template.format(isServerRunning='is not running')
print test
OUTPUT:
Server is not running
NTP is running
Application is running
(假设这3个参数的默认值应该是'正在运行')
感谢您的时间
答案 0 :(得分:0)
你可以在像以下的函数中包含它吗?
def test(isServerRunning='is running',
isNTPrunning='is running',
isAppRunning='is running'):
return template.format(
isServerRunning=isServerRunning,
isNTPrunning=isNTPrunning,
isAppRunning=isAppRunning)