print [i*100+j*10+y for i in range(1,10) for j in range(0,10) for y in range(1,100) if i == y]
2018-04-09
L = []
start = 1
end = 100
for x in range(1,101):
L.append(x*x)
print L
print sum(L)
start = 1
end = 100
for x in range(1,101):
L.append(x*x)
print L
print sum(L)
2018-04-09
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,":",v
print 'average', ':', sum/len(d)
sum = 0.0
for k, v in d.items():
sum = sum + v
print k,":",v
print 'average', ':', sum/len(d)
2018-04-09
d = { 'Adam': 95, 'Lisa': 85, 'Bart': 59, 'Paul': 74 }
sum = 0.0
for i in d.values():
sum+=i
print sum/len(d)
sum = 0.0
for i in d.values():
sum+=i
print sum/len(d)
2018-04-09
函数原型:range(start, end, step):
参数含义:start:计数从start开始。默认是从0开始。例如range(6)等价于range(0, 5);
end:计数到end结束,但不包括end.例如:range(0, 5) 是[0, 1, 2, 3, 4]没有5
step:每次跳跃的间距,默认为1。例如:range(0, 5) 等价于 range(0, 5, 1)
示例
>>> range(5) #代表从0到5(不包含5)
[0, 1, 2, 3, 4]
参数含义:start:计数从start开始。默认是从0开始。例如range(6)等价于range(0, 5);
end:计数到end结束,但不包括end.例如:range(0, 5) 是[0, 1, 2, 3, 4]没有5
step:每次跳跃的间距,默认为1。例如:range(0, 5) 等价于 range(0, 5, 1)
示例
>>> range(5) #代表从0到5(不包含5)
[0, 1, 2, 3, 4]
2018-04-09
#1
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
#2
L = ['Adam', 'Lisa', 'Bart', 'Paul']
k=zip(range(1,len(L)+1),L)
for i in k:
print i[0],'-',i[1]
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for index, name in enumerate(L):
print index+1, '-', name
#2
L = ['Adam', 'Lisa', 'Bart', 'Paul']
k=zip(range(1,len(L)+1),L)
for i in k:
print i[0],'-',i[1]
for x in ['1','2','3','4','5','6','7','8','9' ]:
for y in ['0', '1','2','3','4','5','6','7','8','9' ]:
if x<y:
print x*1+y
for y in ['0', '1','2','3','4','5','6','7','8','9' ]:
if x<y:
print x*1+y
2018-04-09
sum = 0
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
x = 0
while True:
x = x + 1
if x > 100:
break
if x%2==0:
continue
sum=sum+x
print sum
2018-04-09
t = tuple(range(0,10))
# t = ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )
print t
# t = ( 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 )
print t
2018-04-08
方法一:
print [int(str(a) + str(b) + str(c)) for a in range(1,10) for b in range(0,10) for c in range(0,10) if str(a)==str(c)]
方法二:
print [x for x in range(100,1000) if (x/100) == (x%10)]
print [int(str(a) + str(b) + str(c)) for a in range(1,10) for b in range(0,10) for c in range(0,10) if str(a)==str(c)]
方法二:
print [x for x in range(100,1000) if (x/100) == (x%10)]
2018-04-08