DAY 27
2
Software Development

## 傳值

``````var a = 'Ray';
var b = a;
b = 'QQ';

console.log(a, b); // Ray, QQ
``````

``````a = 'Ray'
b = a
b = 'QQ'

print(a, b) # Ray, QQ
``````

``````def fn(x, y):
cache = 100
x = cache
y = x

x = 10
y = 20

fn(x, y)

print(x, y) # 10, 20
``````

``````def fn(x, y):
cache = 100
global x, y # SyntaxError: name 'x, y' is parameter and global
x = cache
y = x

x = 10
y = 20

fn(x, y)

print(x, y) # 10, 20
``````

「或許 Python 的數值型別、字串型別與布林型別會與 JavaScript 的原始型別類似？」

``````def fn(w, x, y, z):
w = False
x = 10
y = 1.1
z = 'Ray'
print(w, x, y, z) # False, 10, 1.1, Ray

w = True # 布林
x = 9.9 # 浮點數
y = 'Ray' # 字串
z = 10 # 整數

fn(w, x, y, z)

print(w, x, y, z) # True, 9.9, Ray, 10
``````

## 傳參考

``````var b = {
name: 'Ray',
};

var e = b;

e.name = 'QQ';
console.log(b.name); // QQ
``````

``````b = {
'name': 'Ray'
}

e = b

e['name'] = 'QQ'
print(b['name']) # QQ
``````

``````def fn (x):
x['name'] = 'QQ'

b = {
'name': 'Ray'
}

fn(b)

print(b['name']) # QQ
``````

``````def fn (x):
x = {
'name': 'Ray'
}

b = {
'name': 'Ray'
}

fn(b)

print(b['name']) # Ray
``````

``````# 把字典看成一個車殼，裡面放著車子的東西
car = {
'steeringWheel': 1, # 方向盤
'wheels': 4, # 輪胎
}
``````

``````car = {
'steeringWheel': 1,
'wheels': 4,
}

ray = car
``````

``````car = {
'steeringWheel': 1,
'wheels': 4,
}

ray = car
ray['wheels'] = 3

print(car['wheels']) # 3
``````

``````car = {
'steeringWheel': 1,
'wheels': 4,
}

ray = car

ray = {
'steeringWheel': 1,
'wheels': 4,
}
``````

``````car = {
'steeringWheel': 1,
'wheels': 4,
}

ray = car

ray = {
'steeringWheel': 1,
'wheels': 4,
}

``````

``````car = {
'steeringWheel': 1,
'wheels': 4,
}

ray = car

print(id(ray), id(car)) # 4463682048, 4463682048
``````

``````car = {
'steeringWheel': 1,
'wheels': 4,
}

ray = car

ray = {
'steeringWheel': 1,
'wheels': 4,
}

print(id(ray), id(car)) # 4418249408 4418249216
``````

## call by xxx

``````a = 'Ray'
b = 'Ray'

print('a', a, id(a)) # a Ray 4351631984
print('b', b, id(b)) # b Ray 4351631984
``````