Python วนลูปบน list ที่โตขึ้นเรื่อยๆ

a = [1]
for i in a:
    print i
    if len(a) < 10:
        a.append(i+1)

ได้ผลลัพธ์เป็น
1
2
3
4
5
6
7
8
9
10

ตื่นเต้นดี for loop บน list ที่โตขึ้นเรื่อยๆ… ไม่รู้ว่าจะจบเมื่อไหร่

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out /  เปลี่ยนแปลง )

Connecting to %s