print [int(x+y+x) for x in '123456789' for y in '0123456789']
2015-09-17
def average(*args):
return float(sum(args)) and float(sum(args)) / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
return float(sum(args)) and float(sum(args)) / len(args)
print average()
print average(1, 2)
print average(1, 2, 2, 3, 4)
2015-09-17
d = {
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'adam:', d['Adam']
if 'Lisa' in d:
print 'lisa:',d['Lisa']
if d.get('Bart'):
print 'bart:',d['Bart']
'Adam': 95,
'Lisa': 85,
'Bart': 59
}
print 'adam:', d['Adam']
if 'Lisa' in d:
print 'lisa:',d['Lisa']
if d.get('Bart'):
print 'bart:',d['Bart']
2015-09-17
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
最新回答 / Piggyg
比如两个字符串相加 a='good' b='moring' ,那么a+b 打印出来就是 good morning然而数字和字符串不能相加, a+1是打印不出来结果的,然而如果是a+'1'就会打印出good 1,因为此时'1'是字符串逗号可以分割开打印的各个对象
2015-09-16