Python Forum
Q. Nested for statement in list type
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Q. Nested for statement in list type
#1
Hi, i'm beginner python, this is my source

tList = [[None]*3]*9

for j in range(0, 9):
    for k in range(0, 3):
        if(k==0 and j==0):
            tList[j][k] = 2
        elif(k==1):
            tList[j][k] = 4
        elif(k==2):
            tList[j][k] = 5
    print(j, k)
print(tList)
I don't understand result.
j count increase is ok in for statement
Especially, why changed '2' in tList[1][0] ?
plz help me.
Reply


Messages In This Thread
Q. Nested for statement in list type - by ives - Mar-14-2018, 01:17 AM
RE: Q. Nested for statement in list type - by ives - Mar-14-2018, 07:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  convert set to a list type in python firaki12345 2 1,702 Feb-05-2021, 03:45 PM
Last Post: buran
  error when inserting list statement from python to MySQL ADBYITMS 0 1,547 Nov-10-2019, 10:44 AM
Last Post: ADBYITMS

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020