상세 컨텐츠

본문 제목

Mutable, Immutable

Python

by techbard 2024. 12. 23. 17:06

본문

반응형

 

# Mutable object
l = [1, 2, 3]
print(f"Address of l is {id(l)}")
l += [4]
print(f"Address of l is {id(l)}")

# Immutable object
s = 'abc'
print(f"Address of s is {id(s)}")
s += 'd'
print(f"Address of s is {id(s)}")

# Output:
Address of l is 1621540708864
Address of l is 1621540708864
Address of s is 1621541747712
Address of s is 1621542153616
반응형

관련글 더보기

댓글 영역