目前來說, 這樣的解釋是最恰當不過的....
List的表示是利用 [](一組方括號)來定義的, 在一個list裡面,
你可以有多個數值放在裡面, 如下面的例子
ex1:
>>> integer_list=[1,2,3,4] -->整數的list
>>> string_list=['a','b','c'] -->字串的list
>>> combine_list=integer_list + string_list -->混合式的list
>>> combine_list
[1, 2, 3, 4, 'a', 'b', 'c']
ex2:利用for 回圈把數值讀出
>>> for i in combine_list: -->定義了一個變數i
... print i -->列印變數i, 在此要空兩格, 因為Python寫法要求有固定的形式
...
1
2
3
4
a
b
c
ex3:如何倒印上面的例子
>>> combine_list.reverse()
>>> for i in combine_list:
... print i
...
c
b
a
4
3
2
1
ex4: 如何知道list的長度?
>>> list
[1, 2, 3]
>>> len(list)
3
>>>
Actually, there's an array module, which is less flexible but more efficient than list when doing numerics. Also, numpy provides another kind of array(?) with tons of powerful functions.
回覆刪除numpy is a better thing to do numeric array. I should give out more details on it. Happy to see your comments here. :)
回覆刪除