所以我在Python 2.7遇到了一個有趣的現象,我的好奇,想知道爲什麼會發生。我定義了以下4層的數據結構在python 2.7:Python對象分配地址
- 甲設置爲 'ST'
- 甲列表 'LST'
- 甲元組'TPL '
- A dictionary as'DCT「
使用Python創建它們:
st = set(['apple', 'orange', 'apple', 'pear', 'orange', 'banana'])
lst = [1, 2, 3, "4"]
tpl = (1, 2, 3, '4')
dct = {'one': 1, 'two': 2, 'three': 3};
這裏是4個對象的表示:
st.__repr__
<method-wrapper '__repr__' of set object at 0x7f234997ba48>
tpl.__repr__
<method-wrapper '__repr__' of tuple object at 0x7f23499667e0>
lst.__repr__
<method-wrapper '__repr__' of list object at 0x7f2349910b48>
dct.__repr__
<method-wrapper '__repr__' of dict object at 0x25af3a0>
正如你所看到的,我的字典裏被放置在一個完全不同的存儲器部分(0x25af3a0)與其他(0x7f23499 *****)相比較。
我的問題是,爲什麼字典對象被置於一個完全不同的內存段?
Python版本是2.7.3(在linux上用GCC 4.7.2編譯),linux版本是3.18.0-kali3-amd64#1 SMP Debian 3.18.6-1〜kali2(2015-03-02) x86_64 GNU/Linux)。
是一個問題? 有什麼,你需要做的地址?只是一個查詢! – Ja8zyjits
沒問題,我只想知道它爲什麼會發生。是的,我[再次嘗試](http://pastebin.com/2zvR3W3D),字典又放到了不同的地方。 –
地址空間佈局隨機化在行動? – tynn