데이터 구조 및 분석 ch_1_9 Assignment and Equivalence
Jul 4, 2021
»
writing
KAIST 산업및시스템공학과 문일철_ 데이터 구조 및 분석 수업을 참고하여 작성하였습니다
ch_1_9 Assignment and Equivalence
Assignment and Equivalence
1. Assignment and Equivalence : One variable's value is changed : But, you see three changes : Becuase - reference - x has two references from y and z - values of y and z are determined by x - x is changed : "=="checks the equivalence of two referenced values (두개의 레퍼런스) : "is" checks the equivalence of two referenced objets' IDs (같은 위치)
x = [1, 2, 3]
Y = [100, x, 120] # nested (둥지속)
z = [x, 'a', 'b']
print('x is ', x)
print('Y is ', Y)
print('z is ', z)
x[1] = 2021
print('\nx is ', x)
print('Y is ', Y)
print('z is ', z)
x[1] = 2
x2 = [1,2,3]
if x == x2:
print('Values are equivalent')
else :
print('Values are not equivalent')
if x is x2 :
print('Values are stored at the same place')
else :
print('Values are not stored at the same place')
if x[1] is Y[1][1] :
print('Values are stored at the same place')
else :
print('Values are not stored at the same place')
# x is [1, 2, 3]
# Y is [100, [1, 2, 3], 120]
# z is [[1, 2, 3], 'a', 'b']
# x is [1, 2021, 3]
# Y is [100, [1, 2021, 3], 120]
# z is [[1, 2021, 3], 'a', 'b']
# Values are equivalent
# Values are not stored at the same place
# Values are stored at the same place