-- 어느 블로그


Java는 Call by value, Ruby는 Call by reference. Python은 둘 다 아님. 공식 manual에는 call by assignment라고 되어 있음.(call by object, call by object reference라는 말도..) 그것이 무엇인지 이해하기 위해서는 일단 Python에선 모든 것이 객체(object)이고, 그 객체에는 2가지 종류가 있다는 것을 알아야 함.


immutable object 

immutable object인 int, float, str, tuples 등이 함수 arguments로 넘어갈 땐 call by value로 넘어감. subprogram에서 formal parameter 값들이 아무리 바뀌어도, actual parameter에는 영향이 없음.


mutable object 

list, dict, set 와 같이 mutable object가 argument로 넘어가면 object reference가 넘어가서 담고 있는 값이 바뀔 수도 있음. 


-- 내 반론


immutable이나 mutable이나 call by reference로 넘어간다.

단, 이후 해당 변수에 새로 할당할 때 immutable이 새로운 객체로 변신할 뿐(이부분은 파이썬의 기초)


증거는 아래와 같음


def test(string):

    print(id(string)) # 140659604510008

    string = 'new world'

    print(id(string)) # 140659604514032


string = 'word'

print(id(string)) # 140659604510008

test(string)