1
我正在學習Python並正在從本書學習潛入Python。它說:附加一個值返回值的函數範圍()
The built−in
range
function returns a list of integers. In its simplest form, it takes an upper limit and returns a zero−based list counting up to but not including the upper limit.
根據它說的,它返回一個列表。我認爲我可以用追加函數給它添加一個值,但我不能。
>>> l = range(7)
>>> l
[0, 1, 2, 3, 4, 5, 6]
>>> l.append(13)
>>> l
[0, 1, 2, 3, 4, 5, 6, 13]
>>> l = range(7).append(13)
>>> l
它不打印任何東西,是什麼原因?
備註:'range'只返回Python 2.x中的列表。在Python 3中,你會得到一個'AttributeError:'範圍'對象沒有屬性'append'' –