Python 将变量值添加到带有三个引号的字符串中
我有一个变量定义如下:Python 将变量值添加到带有三个引号的字符串中,python,html,api,Python,Html,Api,我有一个变量定义如下: item_title="Title" 我想把这个值放到下面的字符串中: html_desc=""" <![CDATA[ <head> <style> body { font-size: 25px; border-style: solid; border-width: 5px; border-color: green; border-radius: 10px; backgroun
item_title="Title"
我想把这个值放到下面的字符串中:
html_desc="""
<![CDATA[
<head>
<style>
body {
font-size: 25px;
border-style: solid;
border-width: 5px;
border-color: green;
border-radius: 10px;
background-color: #FFFFC2;
padding: 15px;
}
li {
color: #F7270F;
font-weight: bold;
}
</style>
</head>
<body>
<h1 align="center">Auctions for Week of 08-01-2018</h1>
<p>You are bidding on the following item:</p>
<ul><li>"{}".format(item_title)</li></ul>
<p>Condition is pack fresh unless otherwise indicated. Please review the pictures carefully and if you have any questions about something specific, ask.</p>
<p><b>Shipping:</b> Shipping will be calculated based on buyer location. No premiums are charged. Cards are mailed in an 8x5 bubble mailer and shipped First Class mail unless the price exceeds $50, at which point they will be shipped Priority at no additional cost to the buyer. If you win multiple auctions, please wait for an invoice to be sent.</p>
</body>
]]>"""
html_desc=”“”
身体{
字体大小:25px;
边框样式:实心;
边框宽度:5px;
边框颜色:绿色;
边界半径:10px;
背景色:#FFFFC2;
填充:15px;
}
李{
颜色:#F7270F;
字体大小:粗体;
}
2018年1月8日一周的拍卖
您正在对以下项目进行投标:
格式(项目名称)
除非另有说明,否则包装条件是全新的。请仔细查看图片,如果您对某些特定内容有任何疑问,请询问
配送:配送将根据买家所在地进行计算。不收取任何保费。卡将使用8x5气泡邮递器进行邮寄,并以头等邮件进行配送,除非价格超过50美元,在这一点上,这些卡将优先配送,不会给买家带来额外费用。如果您赢得多次拍卖,请等待发票发送
]]>"""
我在这里的尝试失败了。我还尝试在最后三个“”之后的末尾使用{}和.format,但这也不起作用
有什么帮助吗?您不能使用格式,因为您在样式部分中使用了这些
{}
括号,但您可以通过加号操作符(+
)轻松完成,如:-
html_desc=”“”
身体{
字体大小:25px;
边框样式:实心;
边框宽度:5px;
边框颜色:绿色;
边界半径:10px;
背景色:#FFFFC2;
填充:15px;
}
李{
颜色:#F7270F;
字体大小:粗体;
}
2018年1月8日一周的拍卖
您正在对以下项目进行投标:
- “+项目名称+”
除非另有说明,否则包装条件为全新。请看图片
如果你对某些特定的事情有任何疑问,请仔细询问
装运:装运将根据买方所在地进行计算。不收取保险费。除非价格超过50美元,否则卡将在8x5气泡邮递器中邮寄,并以头等邮件方式寄送,此时将优先寄送,买方不承担任何额外费用。如果您赢得多次拍卖,请等待发票发送
]]>"""
您不能使用格式,因为您在样式部分中使用了这些{}
括号,但您可以通过加号操作符(+
)轻松地使用格式,如:-
html_desc=”“”
身体{
字体大小:25px;
边框样式:实心;
边框宽度:5px;
边框颜色:绿色;
边界半径:10px;
背景色:#FFFFC2;
填充:15px;
}
李{
颜色:#F7270F;
字体大小:粗体;
}
2018年1月8日一周的拍卖
您正在对以下项目进行投标:
- “+项目名称+”
除非另有说明,否则包装条件为全新。请看图片
如果你对某些特定的事情有任何疑问,请仔细询问
装运:装运将根据买方所在地进行计算。不收取保险费。除非价格超过50美元,否则卡将在8x5气泡邮递器中邮寄,并以头等邮件方式寄送,此时将优先寄送,买方不承担任何额外费用。如果您赢得多次拍卖,请等待发票发送
]]>"""
请在代码末尾,在三个“”之后,用,format()调用发布代码。应该可以:。format是str类的方法,不知道str对象是如何定义的。如果文本使用1或3个引号,则不重要。请在代码末尾,在三个“.”之后,使用,format()调用发布代码。这应该有效:。format是类str的方法,不知道str对象是如何定义的。如果文本使用1或3个引号,则不重要。
html_desc="""
<![CDATA[
<head>
<style>
body {
font-size: 25px;
border-style: solid;
border-width: 5px;
border-color: green;
border-radius: 10px;
background-color: #FFFFC2;
padding: 15px;
}
li {
color: #F7270F;
font-weight: bold;
}
</style>
</head>
<body>
<h1 align="center">Auctions for Week of 08-01-2018</h1>
<p>You are bidding on the following item:</p>
<ul><li>""" + item_title + """</li></ul>
<p>Condition is pack fresh unless otherwise indicated. Please review the pictures
carefully and if you have any questions about something specific, ask.</p>
<p><b>Shipping:</b> Shipping will be calculated based on buyer location. No premiums are charged. Cards are mailed in an 8x5 bubble mailer and shipped First Class mail unless the price exceeds $50, at which point they will be shipped Priority at no additional cost to the buyer. If you win multiple auctions, please wait for an invoice to be sent.</p>
</body>
]]>"""