根據this question on Stack Overflow,Python中的賦值始終是值,因此您無法更改原始源。例如(來自同樣的問題),Python的字典視圖對象是否按值賦予其賦值異常
locs = [ [1], [2] ]
for loc in locs:
loc = []
print locs
# prints => [ [1], [2] ]
然而,字典視圖對象示出了相反的行爲
bike = {"Manufacturer":"Honda","Model":"CBR","cc":250,"price":70,"mileage":74}
keys = bike.keys()
print(keys)
bike["tyres"] = 2
print(keys)
這是輸出:
dict_keys(['mileage', 'price', 'Model', 'Manufacturer', 'cc'])
dict_keys(['cc', 'Manufacturer', 'tyres', 'mileage', 'Model', 'price'])
可以它們被視爲例外以賦值性質?如果是的話,那麼Python3中的其他例外情況如何?