def add_div(filename, caption):
test = str(filename)
return ('<div><img src=' + test + '><br><p>' + caption + '</p></div>')
def add_body(image_dict, s, order = None):
'''(dict of {str:list of str}, str, list) -> str
If the third parameter is passed, then the filenames
included in the body should only be those in the list and should be added
in the same order as they are listed in the list. '''
new = ''
s = '<html><head></head>'
while order is None:
for (key, value) in image_dict.items():
new += add_div(str(key), str(value[2]))
return (s + '<body><div id="slideshow">' + new + '</body>'+ '</html>')
如何在图片/ skater.jpg周围加上引号?
答案 0 :(得分:2)
您有两个不同的选项:
1)使用双引号
print("Hey that's pretty cool!")
2)转义单引号
print('Hey that\'s pretty cool!')
答案 1 :(得分:0)
您可以在串联的字符串中包含引号,如下所示:
def add_div(filename, caption):
test = str(filename)
return ('<div><img src="' + test + '"><br><p>' + caption + '</p></div>')
答案 2 :(得分:0)
对quotation
定义使用一种string
,为包含的quotes
使用另一种类型:
>>> "bob said: 'hello'"
"bob said: 'hello'"
>>> "I said 'yo bob, how u doing?' in reply"
"I said 'yo bob, how u doing?' in reply"
为了解决您的问题,只需将第一个return
中的function
语句更改为:
return ('<div><img src="' + test + '><br><p>'" + caption + '</p></div>')
请注意,最后,return
语句中的括号不是必需的,因为return
不是function
或method
的
答案 3 :(得分:0)
答案很好,但另一种方法是使用\
示例:
# this is the same as
# s = "'"
s = '\''
print(s)
#this is the same as
# s = '"'
s = "\""
print(s)