1. 학습목표
2. 학습내용
# 함수 매객변수 전달 사용
def mul(x, y):
x += y
return x
x = 10
y = 5
# print('EX6-1', mul(x,y), x, y)
# EX6-1 15 10 5
# 가변형인 매개변수를 전달하면 원본 데이터가 변경된다!
a = [10, 100]
b = [5, 10]
# print('EX6-2', mul(a,b),a, b)
# EX6-1 [10, 100, 5, 10] [10, 100, 5, 10] [5, 10]
# 불변형인 매개변수를 전달할 때는 원본 데이터는 변경안됨!!!
c = (10,100)
d = (5,10)
# print('EX6-3', mul(c,d),c, d)
# EX6-3 (10, 100, 5, 10) (10, 100) (5, 10)
# 파이썬에서 불변형이지만 같은 주소값을 보는 예외의 경우!
# str, bytes, frozenset, tuple: 사본생성하지 않고 "참조"를 반환!
# 이유는 성능을 위해서 파이썬이 이렇게 만듬!
tt1 = (1,2,3,4,5)
tt2 = tuple(tt1)
tt3 = tt1[:]
# print('EX7-1 -', tt1 is tt2, id(tt1), id(tt2))
# EX7-1 - True 4337259800 4337259800
# print('EX7-2 -', tt3 is tt1, id(tt3), id(tt1))
# EX7-2 - True 4319434008 4319434008
tt4 = (10,20,30,40,50)
tt5 = (10,20,30,40,50)
ss1 = 'apple'
ss2 = 'apple'
# print('EX7-3 -', tt4 is tt5, tt4 == tt5, id(tt4), id(tt5))
# EX7-3 - True True 4335946744 4335946744
# print('EX7-4 -', ss1 is ss2, ss1 == ss2, id(ss1), id(ss2))
# EX7-4 - True True 4328841992 4328841992
3. 느낀 점