L=[]
for x in range(1,10):
for y in range(0,10):
z=x*100+y*10+x
L.append(z)
print L
for x in range(1,10):
for y in range(0,10):
z=x*100+y*10+x
L.append(z)
print L
2020-06-21
print [m*100+n*10+k for m in range(1,10) for n in range(0,10) for k in range(0,10) if m==k]
2020-06-21
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
n = 0
sum = 0.0
for v in d.itervalues() :
sum = sum + v
n = n + 1
print sum * 1.0 / n
n = 0
sum = 0.0
for v in d.itervalues() :
sum = sum + v
n = n + 1
print sum * 1.0 / n
2020-06-20
最赞回答 / Troms
顺序不一样,结果当然不一样!第一个是先对sum进行累计,然后计数项x进行+2第二个是先对计数项x进行+2,然后再累计到sum里去那当然是第二个结果会多了一位x的值。先吃饭再称体重和先称体重再吃饭,显示的值不一样。
2020-06-20
def firstCharUpper(s):
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
return s[0].upper()+s[1:]
print firstCharUpper('hello')
print firstCharUpper('sunday')
print firstCharUpper('september')
2020-06-19
1.因为a为非空字符串,所以看成True,在or关系中,则结果为True,返回a;
2.因为b为空字符串,所以看成False,在or关系中,返回结果取决于另外一个字符串,即‘world’,非空,则结果为True,返回‘wrold’
2.因为b为空字符串,所以看成False,在or关系中,返回结果取决于另外一个字符串,即‘world’,非空,则结果为True,返回‘wrold’
2020-06-19