print [x*100+y*10+z for x in range(1,10) for y in range(0,10) for z in range(1,10) if x==z ]
2016-08-31
def generate_tr(name, score):
if score<60:
return '<tr><td>%s</td><td style="color:red">%s</td></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()]
if score<60:
return '<tr><td>%s</td><td style="color:red">%s</td></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()]
2016-08-31
最赞回答 / 慕粉13726259791
if x % 2 == 1 and x<=100: 这句应该分为俩句,and 的话是与运算,若判断 x % 2 == 1为假的话,x <= 100 就不会执行下去的了,再结合上面小伙伴说的,再用break语句进行 x 的值判断
2016-08-31
>>> print r'"hahaha"'
"hahaha"
可以呀
"hahaha"
可以呀
2016-08-31
# -*- coding: utf-8 -*-
d = {
95 : 'Adam',
85 : 'Lisa',
59 : 'Bart',
}
for key,values in d.items():
print key + ':' + values
d = {
95 : 'Adam',
85 : 'Lisa',
59 : 'Bart',
}
for key,values in d.items():
print key + ':' + values
2016-08-31
sum = 0
x = 0
while True:
x = x + 1
if x%2 == 0:
continue
if x > 100:
break
sum += x
print sum
x = 0
while True:
x = x + 1
if x%2 == 0:
continue
if x > 100:
break
sum += x
print sum
2016-08-31
L = [75, 92, 59, 68]
sum = 0.0
for tmp in L:
sum += tmp
print sum / 4
sum = 0.0
for tmp in L:
sum += tmp
print sum / 4
2016-08-31
L = ['A', 'B'] #首先分析一下 L 是个list
t = ('a', 'b', L) #那么在这个tuple中 最后一个元素指向list
t = ('a', 'b', ('A', 'B')) #要使其不变我们可一使最后一个元素 重新指向一个 tuple
print t
t = ('a', 'b', L) #那么在这个tuple中 最后一个元素指向list
t = ('a', 'b', ('A', 'B')) #要使其不变我们可一使最后一个元素 重新指向一个 tuple
print t
2016-08-31
L = ['Adam', 'Lisa', 'Bart']
L.insert(0,L.pop()) #首先把末尾的'Bart'通过pop()方法弹出 然后就变成L.insert(0,'Bart') => L = ['Bart','Adan','Lisa']
L.append(L.pop(1)) # 接着使用L,pop(1) 将 'Adam'弹出 得到 L.append('Adam') => L = ['Bart','List','Adan']
print L
L.insert(0,L.pop()) #首先把末尾的'Bart'通过pop()方法弹出 然后就变成L.insert(0,'Bart') => L = ['Bart','Adan','Lisa']
L.append(L.pop(1)) # 接着使用L,pop(1) 将 'Adam'弹出 得到 L.append('Adam') => L = ['Bart','List','Adan']
print L
2016-08-31
L = ['Adam', 'Lisa', 'Paul', 'Bart']
L.pop(2) #执行L.pop 后 L = ['Adam','Lisa','Bart']
#那么此时list的索引只有 0 1 2
L.pop(3) #这时候我们尝试L.pop(3)的话就会越界 因为L只有 0 1 2的索引 所以将L.pop改成L.pop就可以了
print L
L.pop(2) #执行L.pop 后 L = ['Adam','Lisa','Bart']
#那么此时list的索引只有 0 1 2
L.pop(3) #这时候我们尝试L.pop(3)的话就会越界 因为L只有 0 1 2的索引 所以将L.pop改成L.pop就可以了
print L
2016-08-31