copy(Shallow and deep copy operations) copy — Shallow and deep copy operations — Python 3.7.4rc2 documentation copy — Shallow and deep copy operations Source code: Lib/copy.py Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed docs.python.org
변수는 상자가 아니다 파이썬에서 변수는 이름표 파이썬 변수는 자바에서의 참조 변수와 같다. 변수는 객체에 붙은 레이블이다 a = [1, 2, 3] b = a a.append(4) b # [1, 2, 3, 4] 참조 변수의 경우 변수가 객체에 할당되었다는 표현이 객체를 변수에 할당했다는 표현보다 훨씬 타당. 결국 객체는 변수가 할당되기 전에 생성 된다. class Gizmo: def __init__(self): print('Gizmo id: %d' % id(self)) x = Gizmo() # Gizmo id: 4301489152 y = Gizmo() * 10 # Gizmo id: 4301489432 # 곱셈을 시도하기 전에 Gizmo 객체가 실제로 생성되었음을 입증 # TypeError: unsuppor..
import dis dis.dis('a = [1, 2, 3, 4]') """ 0 LOAD_CONST 0 (1) 2 LOAD_CONST 1 (2) 4 LOAD_CONST 2 (3) 6 LOAD_CONST 3 (4) 8 BUILD_LIST 4 10 STORE_NAME 0 (a) 12 LOAD_CONST 4 (None) 14 RETURN_VALUE """ dis(Disassembler for Python bytecode) dis — Disassembler for Python bytecode — Python 3.7.4rc2 documentation dis — Disassembler for Python bytecode Source code: Lib/dis.py The dis module supports the a..