for x in range(1,10):
for y in range(0,10):
if x < y:
print str(x) + str(y)
for y in range(0,10):
if x < y:
print str(x) + str(y)
2015-09-17
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
# for key,value in d.iteritems():
# print key,':',value
L=[]
for key in d:
L.append(key)
L[0],L[1]=L[1],L[0]
# print L
for x in L:
print x,':',d[x]
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
# for key,value in d.iteritems():
# print key,':',value
L=[]
for key in d:
L.append(key)
L[0],L[1]=L[1],L[0]
# print L
for x in L:
print x,':',d[x]
2015-09-17
print [(x*100+y*10+z*1) for x in range(1,10) for y in range(0,10) for z in range(1,10) if x==z]
2015-09-17
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for x in s:
print x[0],':',x[1]
for x in s:
print x[0],':',x[1]
2015-09-16
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for i in d:
print i,':',d.get(i)
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
for i in d:
print i,':',d.get(i)
2015-09-16
因为在python中,0 空字符串,以及None都看做是False,其他数值和非空的字符串看作是True
短路计算规则:当为与运算时,a and b 如果,a为false,那么结果为false ,不再运算b的结果,a为true是,要看b的结果,
当为或运算时,a or b 如果 a为true,那么结果为true,不再运算b的结果,a为假时,要看b的结果。
短路计算规则:当为与运算时,a and b 如果,a为false,那么结果为false ,不再运算b的结果,a为true是,要看b的结果,
当为或运算时,a or b 如果 a为true,那么结果为true,不再运算b的结果,a为假时,要看b的结果。
2015-09-15
def average(*args):
if len(args)==0:
return 0.0
a=sum(args)
b=len(args)
return float(a)/b
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
if len(args)==0:
return 0.0
a=sum(args)
b=len(args)
return float(a)/b
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-09-15