倒數第二行代碼中的‘\n’是什么意思
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
??? return '<tr><td>%s</td><td>%s</td></tr>' % (name, score)
tds = [generate_tr(name, score) for name, score in d.iteritems()]
print '<table border="1">'
print '<td style="color:red">'
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
print '</table>'
2019-09-10
轉義字符, 換行的意思。html中換行用標簽<br/>。個人認為這里只是充當一個字符串的角色,將'\n'換成任何字符串如'aaaa'等,甚至是空字符串''也是也是可以的,因為最后生成的html代碼中,這個字符串并不在標簽中,所以,字符串無論是什么內容都不會顯示。非要加這個字符串是因為join()是一個字符串方法,語法格式規定如此。