概述
对python中list的操作,大家可以参考:
效果:
下面有更多的demo:
<div class="cnblogs_code">
Python 3.3.2 (v3.3.2:d047928ae3f6,00:03:43) [MSC v.1600 32 Type , >>> counter = 100
>>> miles = 1000.0
>>> name =
>>> numberA,numberB,nameC = 1,
>>> list = >>> [100,1000.0,, >>>
>>> element
100
1000.0
1
2
>>>
>>> (list[0]) 获取列表list里面的第一个元素值
100
>>> (list[-1]) 获取列表list里面的最后一个元素值
>>> (len(list)) 获取list列表的长度
6
>>> num_inc_list = range(10) 一个数值递增的列表
>>> range(0,10 >>> inc_list
1
2
3
4
5
6
7
8
9
>>> 一个从0开始到9的一个数值递增列表
>>> initial_value = 10
>>> list_length = 5
>>> myList = [initial_value i range(10 >>> [10,10,10 >>> list_length = 2
>>> myList = myList * >>> [10,10 >>> 20
>>> 一个固定值initial_value去初始化一个列表myList
>>>
>>> 效果
>>> copyList = [1, >>> copyList = copyList * >>> 8
>>> cl
1
2
3
1
2
3
>>>
>>> 一个list中可以包含不同类型的元素,这个和ActionScript 3.0(AS3.0)中的数组类似
>>> test_list = [,, >>> 7
>>> (test_list[0])
>>>
>>> (test_list[-1]) 一个元素
>>> (test_list[-len]) 一个元素
File ,line 1,
(test_list[-len]) 一个元素
TypeError: bad operand type unary -:
>>> (test_list[-len(test_list)]) 一个元素
>>> (test_list[len(test_list) - 1]) 一个元素
>>> test_list.append(6) 一个元素
>>> (test_list[-1 6
>>> test_list.insert(1 >>> [,,6 >>>
>>> test_list.insert(1 >>>