代码问题执行顺序
我的代码:
L=[]
for a in range(1,10):
for b in range(0,10):
for a in range(1,10):
L.append(a*100+b*10+a)
print L
结果为:
[101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999, 101, 202, 303, 404, 505, 606, 707, 808, 909, 111, 212, 313, 414, 515, 616, 717, 818, 919, 121, 222, 323, 424, 525, 626, 727, 828, 929, 131, 232, 333, 434, 535, 636, 737, 838, 939, 141, 242, 343, 444, 545, 646, 747, 848, 949, 151, 252, 353, 454, 555, 656, 757, 858, 959, 161, 262, 363, 464, 565, 666, 767, 868, 969, 171, 272, 373, 474, 575, 676, 777, 878, 979, 181, 282, 383, 484, 585, 686, 787, 888, 989, 191, 292, 393, 494, 595, 696, 797, 898, 999]
有两个问题:
为何我的结果有很多遍呢?
关于for循环嵌套语句的执行:(我理解的执行循环)
第一个for循环里面,还有两个嵌套for循环,那么当第一次执行时,a=1,b=0,a=1,结果为101;第二次,应该是跳回第二个for语句这里,a=1,b=1,a=1.结果为111;第三次为a=1,b=2,a=1,结果为121;这样才对。
为何结果是101、202、303这样的循环呢?