Re: [問題] 關於list的append方法

看板Python作者 (←這人是超級笨蛋)時間8年前 (2017/07/19 02:51), 8年前編輯推噓3(302)
留言5則, 3人參與, 最新討論串2/3 (看更多)
※ 引述《LessonWang (橘白Cat)》之銘言:

07/18 13:53,
pass by reference.
07/18 13:53

07/18 15:44,
跟 C 沒有關係吧, 也不是 pass by reference 不要亂教..
07/18 15:44

07/18 17:45,
??? 所以是 by value?
07/18 17:45

07/18 21:10,
@zerof: By reference 和 by value 的差異不是這樣看的
07/18 21:10

07/18 21:12,
這個議題去 Google 就有一堆資料, 可以試著研究看看
07/18 21:12

07/19 02:03,
我記得書上是說根據傳入參數 mutable/immutable 來分
07/19 02:03

07/19 02:04,
當然你說最底層的實做是用 C 一定是指標只來只去拉...
07/19 02:04

07/19 02:06,
認知就是 by ref, 你要不要貼個參考資料說它不是?
07/19 02:06

07/19 02:21,
stackoverflow 986006 也是討論得亂七八糟XD
07/19 02:21

07/19 02:24,
啊你的認知就是錯的啊, 我就說 Google 就有一堆資料了你都沒有在聽嘛 https://www.google.com.tw/?q=python+call+by+reference 就看前五個結果好不好 1. https://stackoverflow.com/questions/986006 這個上面也有提到, 直接看 accepted answer (同時也是分數最高) Arguments are passed by assignment. [...] the parameter passed in is actually a reference to an object (but the reference is passed by value). 2. https://stackoverflow.com/questions/13299427 [...] while you can't explicitly pass variables by reference in Python [...] 3. http://d.pr/KbZ2AS Is Python call-by-value or call-by-reference? Neither. 4. http://www.python-course.eu/passing_arguments.php The authors who call the mechanism call-by-value and those who call it call-by-reference are stretching the definitions until they fit. Correctly speaking, Python uses a mechanism, which is known as "Call-by-Object", sometimes also called "Call by Object Reference" or "Call by Sharing". 5. http://d.pr/GpSU86 Unfortunately, Python is "pass-by-object-reference", of which it is often said: "Object references are passed by value." 好啦反正眾說紛紜大家都在發明自己的名詞 但是上面好像是有個共通點就是所有人都一致同意 call/pass by reference 是錯的 大guy4這樣 -- 作者 Linux (Windows) 看板 C_and_CPP 標題 [問題] 如何確認是否 free 對記憶體 時間 Fri Nov 2 00:14:03 2012

11/02 00:43,
valgrind, 但 windowns 版的沒試過XD
11/02 00:43

11/02 00:44,
linux 上那真的是不二選擇了
11/02 00:44

11/02 00:45,
我是用 Windows ....>"<
11/02 00:45
-- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 218.161.19.12 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1500403904.A.E95.html ※ 編輯: uranusjr (218.161.19.12), 07/19/2017 02:52:09

07/19 07:24, , 1F
python宣告變數其實是把物件參照(變數名稱)指向物件名
07/19 07:24, 1F

07/19 07:24, , 2F
稱(值) 所以是呼叫物件參照
07/19 07:24, 2F

07/19 08:26, , 3F
真的眾說紛紜 ...
07/19 08:26, 3F

07/19 16:36, , 4F
開發角度上 預設變數都是ref來去預防side effect為佳
07/19 16:36, 4F

07/19 16:38, , 5F
任何assinment都要有心理預期 上保險不會虧
07/19 16:38, 5F
文章代碼(AID): #1PRbZ0wL (Python)
文章代碼(AID): #1PRbZ0wL (Python)