列表

  1. list1 = ['physics', 'chemistry', 1997, 2000]
  2. list2 = [1, 2, 3, 4, 5 ]
  3. list3 = ["a", "b", "c", "d"]

访问列表中的值

  1. #!/usr/bin/python
  2. list1 = ['physics', 'chemistry', 1997, 2000]
  3. list2 = [1, 2, 3, 4, 5, 6, 7 ]
  4. print "list1[0]: ", list1[0]
  5. print "list2[1:5]: ", list2[1:5]

更新列表

  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. list = [] ## 空列表
  4. list.append('Google') ## 使用 append() 添加元素
  5. list.append('Runoob')
  6. print list

删除列表元素

  1. #!/usr/bin/python
  2. list1 = ['physics', 'chemistry', 1997, 2000]
  3. print list1
  4. del list1[2]
  5. print "After deleting value at index 2 : "
  6. print list1