Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jennyonjourney/a69899394551cf5385d94c3c51247aa8 to your computer and use it in GitHub Desktop.
Save jennyonjourney/a69899394551cf5385d94c3c51247aa8 to your computer and use it in GitHub Desktop.
python - call by reference
arr1 = [11,22,33,44]
a = 10
b = a
print("a:", id(a))
print("b:", id(b))
a = 20
print("a:", id(a))
print("b:", id(b))
print('----------')
arr1 = [11,22,33,44]
arr2 = arr1
arr3=[i for i in arr1]
arr4 = arr1.copy()
print('arr1:', arr1, id(arr1))
print('arr2:', arr2, id(arr2))
print('arr3:', arr3, id(arr3))
print('arr4:', arr4, id(arr4))
arr3[2] = 3456
print('arr1:', arr1, id(arr1))
print('arr2:', arr2, id(arr2))
print('arr3:', arr3, id(arr3))
print('arr4:', arr4, id(arr4))
# 리스트로 커피 메뉴를 만들어보자
# 커피이름, 물양, 우유량, 시럽양
coffee = [
['아메리카노',1000,20],
['까페라떼',1000,20,50],
['카라멜마끼아또',1000,20,30,40]
]
# 레시피를 바꿀 수 있다. 까페라떼의 물양을 줄여보자
cr = coffee[1]
cr[1] = 800
print(cr)
print('------------------------')
for cc in coffee:
print(cc)
print('------------------------')
print('카라멜마끼아또에 휘핑그림 50을 추가해주세요.')
cm = coffee[2]
cm.append(50)
print(cm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment