发布时间:2019-07-22 17:39:06编辑:auto阅读(2917)
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59 }
def generate_tr(name, score):
if score < 60: #如果小于60分,表格输出时标红
return '<tr><td>%s</td><td style="color:red">%s</td></tr>'% (name,score)
else:
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 '<caption>'
print u"表格标题"
print </caption>
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
print '</table>'
执行效果:
上一篇: Python--阅读优秀的代码
下一篇: python3 urllib 爬虫乱码问
47485
45787
36785
34318
28956
25590
24437
19607
19103
17628
5459°
6042°
5565°
5633°
6567°
5371°
5371°
5879°
5852°
7164°