2024-04-26 11:43:38 发布
网友
我正试着像这样把htm头和身体和预告片结合起来
message1 = """<html> <head></head> <body><p>""" message2 = 'Hello World!' message3 = """</p></body> </html>""" html_message = join(message1,message2,message3)
但当我打印“html\u消息”时,结果是“\Hello World!\“,为什么会出现反斜杠,我如何删除
我假设您使用的是(错误的)导入方法,但是您可以将percent操作数与字符串一起使用
template = """ <html> <head></head> <body> <p>%(text)s</p> </body> </html> """ html_message = template % {"text":"Hello World!"}
别忘了,变量名格式是:百分号+括号中的名称+格式(s表示字符串)
下面是我将如何连接字符串:
message1 = """<html> <head></head> <body><p>""" message2 = 'Hello World!' message3 = """</p></body> </html>""" html_message = "".join([message1,message2,message3])
您所指的join将文件合并在一起,这些文件通常采用Something/another/thing的形式,因此使用反斜杠。不需要from os.path import basename, join
join
Something/another/thing
from os.path import basename, join
要连接字符串,请使用+符号
+
html_message = message1 + message2 + message3
os.path.join用于创建文件路径,如os.path.join('my', 'script.py')=>;my/script.py
os.path.join
os.path.join('my', 'script.py')
my/script.py
我假设您使用的是(错误的)导入方法,但是您可以将percent操作数与字符串一起使用
别忘了,变量名格式是:百分号+括号中的名称+格式(s表示字符串)
下面是我将如何连接字符串:
您所指的
join
将文件合并在一起,这些文件通常采用Something/another/thing
的形式,因此使用反斜杠。不需要from os.path import basename, join
要连接字符串,请使用
+
符号os.path.join
用于创建文件路径,如os.path.join('my', 'script.py')
=>;my/script.py
相关问题 更多 >
编程相关推荐