>>> d = set(['熊大','熊二','光头强'])
>>> name = '光头强'
>>> if name in d:
... print name
>>> name = '光头强'
>>> if name in d:
... print name
2015-12-10
def square_of_sum(L):
M=[]
for v in L:
M.append(v*v)
return M
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
M=[]
for v in L:
M.append(v*v)
return M
print square_of_sum([1, 2, 3, 4, 5])
print square_of_sum([-5, 0, 5, 15, 25])
2015-12-10
>>> for key in d:
... if d[key]>60:
... print key+" 及格"
... else:
... print key+"不及格"
... if d[key]>60:
... print key+" 及格"
... else:
... print key+"不及格"
2015-12-10
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
d["Paul"] = 75
for key in d:
print key,d[key]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
d["Paul"] = 75
for key in d:
print key,d[key]
2015-12-10
# -*- coding: utf-8 -*-
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for value in d:
if d.get(value)==95:
print d.get(value)
break
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for value in d:
if d.get(value)==95:
print d.get(value)
break
2015-12-10
# -*- coding: utf-8 -*-
def square_of_sum(r):
bb = []
for a in r:
bb.append(a*a)
return sum(bb)
c = [1,2,3]
print square_of_sum(c)
def square_of_sum(r):
bb = []
for a in r:
bb.append(a*a)
return sum(bb)
c = [1,2,3]
print square_of_sum(c)
2015-12-09