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*10+y
for y in [0,1,2,3,4,5,6,7,8,9 ]:
if x<y:
print x*10+y
2014-12-29
最新回答 / 仗剑闯江湖
list从逻辑上可以认为是一个环,索引从0开始,向右递增,向左递减。第一个元素索引是0,那最后一个元素在第一个元素左侧,索引就是-1,倒数第二个索引就是-2喽!这个分片操作没有起始索引,默认从0开始,取到索引-2这个元素左侧的那个元素。分片操作默认情况下是从左向右取元素。
2014-12-29
已经全部学习完,这个教程还是很基础的,入门很不错,但是这个地址没有进阶的教程,需要进阶的告诉大家下:到liaoxuefeng老师的个人主页上学习,www.liaoxuefeng.com
2014-12-28
print [i * 100 +j * 10 + k for i in range(1,10) for j in range(0,10) for k in range(1,10) if i==k]
2014-12-28
sum = 0
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
break
print sum
x = 1
n = 1
while True:
sum = sum + x
x = x * 2
n = n + 1
if n > 20:
break
print sum
2014-12-27
L = [75, 92, 59, 68]
sum = 0.0
for score in L:
# sum += score
sum = sum + score
print sum / 4
ps:sum = 0.0 是为了定义sum为浮点型
sum = 0.0
for score in L:
# sum += score
sum = sum + score
print sum / 4
ps:sum = 0.0 是为了定义sum为浮点型
2014-12-27