double assign in python results in identical lists even when different operation is done. Why? -


this question has answer here:

i'm facing situation can't crack logic behind.

i have piece of code

user_id = user_email = [] id, email in users:      # users tuple of tuples looks ((a,b),(c,d)...)     user_id.append(id)     user_email.append(email) 

when check result, found user_id == user_email

when assign them separately, can correctly id's , email's, instead of 2 identical lists contain both id's , email's

i'm wondering what's logic behind double assign , causes phenomenon happen.

when set

user_id = user_email = [] 

you link user_id , user_email 1 list. when list changes both variables change.

set these variables separately.

user_id = [] user_email = [] 

this can confusing if coming language c. think of variable in python name not variable.

this incredibly helpful


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -