d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.iteritems():
sum = sum + v
print k,':',v
print 'average', ':', sum/len(d)
2016-01-13
我想复杂了……
t = ('a', 'b', [('A',), ('B',)])
t = ('a', 'b', [('A',), ('B',)])
2016-01-13
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for x in L:
if x in s:
s.remove(x)
else:
s.add(x)
print s
2016-01-12
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name+':',d[name]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for name in d:
print name+':',d[name]
2016-01-12
因为当age = 20时,满足代码if age >= 6:
print 'teenager'
所以执行完对应的代码块,后面的条件判断就直接忽略,未执行age >= 18的判断,所以结果不是adult
print 'teenager'
所以执行完对应的代码块,后面的条件判断就直接忽略,未执行age >= 18的判断,所以结果不是adult
2016-01-12
L = ['Adam', 'Lisa', 'Bart']
p=L[2]
L[2]=L[0]
L[0]=p
print L
p=L[2]
L[2]=L[0]
L[0]=p
print L
2016-01-12