# -*- coding: utf-8 -*-
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
2015-12-07
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
这个不错
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'Adam:',d['Adam']
print 'Lisa:',d['Lisa']
print 'Bart:',d['Bart']
这个不错
2015-12-07
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print d.get('Adam')
print d.get('Lisa')
print d.get('Bart')
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print d.get('Adam')
print d.get('Lisa')
print d.get('Bart')
2015-12-07
d = {
'Adam':95,
'Lisa':85,
'Bart':59,
'Paul':75
}
'Adam':95,
'Lisa':85,
'Bart':59,
'Paul':75
}
2015-12-07
for x in [ '1','2','3','4','5','6','7','8','9' ]:
for y in [ '2','3','4','5','6','7','8','9' ]:
if x < y
print x + y
for y in [ '2','3','4','5','6','7','8','9' ]:
if x < y
print x + y
2015-12-07
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k,v in d.items():
print k,':',v
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for k,v in d.items():
print k,':',v
2015-12-07
d = {
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72] = ('Paul')
print d
95: 'Adam',
85: 'Lisa',
59: 'Bart'
}
d[72] = ('Paul')
print d
2015-12-07
方法一:
# -*- coding: utf-8 -*-
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
if d[85] == name:
print name
方法二:
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
#score = 85
for name in d:
if d[name] == 85:
print name
# -*- coding: utf-8 -*-
d = {
95:'Adam',
85:'Lisa',
59:'Bart'
}
if d[85] == name:
print name
方法二:
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
#score = 85
for name in d:
if d[name] == 85:
print name
2015-12-07
s = set(['Adam', 'Lisa', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for name in L:
if name in s:
s.remove(name)
else:
s.add(name)
print s
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for name in L:
if name in s:
s.remove(name)
else:
s.add(name)
print s
2015-12-07
# -*- coding: utf-8 -*-
a = ('Adam',)
b = ('Lisa',)
c = ('Bart',)
d = {
'95':a,
'85':b,
'59':c
}
print d.get('95')[0]
a = ('Adam',)
b = ('Lisa',)
c = ('Bart',)
d = {
'95':a,
'85':b,
'59':c
}
print d.get('95')[0]
2015-12-07