加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python开发_python中的list操作

发布时间:2020-12-17 00:18:08 所属栏目:Python 来源:网络整理
导读:对python中list的操作,大家可以参考: [ , , ,1,3,5 [x x range(1,10 s != test_listA = ( * 50 test_listB = ( * 50 test_listC = ( * 50 test_str = test_listD = == main() Python 3.3.2 (v3.3.2:d047928ae3f6,May 16 2013,00:03:43) [MSC v.1600 32 , >

对python中list的操作,大家可以参考:

[,,,1,3,5 [x x range(1,10 s != test_listA = ( * 50 test_listB = ( * 50 test_listC = ( * 50 test_str = test_listD = == main()

Python 3.3.2 (v3.3.2:d047928ae3f6,May 16 2013,00:03:43) [MSC v.1600 32, >>> ================================ RESTART ================================ >>> [,5 [1,2,4,5,6,7,8,9 [, ,,,,,,,,,,,,,,,,>>>

下面有更多的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]) 
 100
 >>> (list[-1]) 
  >>> (len(list)) 
 6
 >>> num_inc_list = range(10) 
 >>>  range(0,10 >>>  inc_list       
  1
 2
 3
 4
 5
 6
 7
 8
 9
 >>> 
 >>> initial_value = 10
 >>> list_length = 5
 >>> myList = [initial_value  i  range(10 >>>  [10,10,10 >>> list_length = 2
 >>> myList = myList * >>>  [10,10 >>>  20
 >>> 
 >>> 
 >>> 
 >>> copyList = [1, >>> copyList = copyList * >>>  8
 >>>  cl       
     
 1
 2
 3
  1
 2
 3
  >>> 
 >>> 
 >>> 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 >>>  [,6 >>> test_list.insert(2,1 >>>  [,6 >>> (test_list.pop(0)) 
  >>>  [0,6 >>> (test_list.pop(2)) 
  >>>  [0,6 >>> test_list.remove(1 >>>  [0,6 >>> 
 >>> test_list.insert(0,1 >>>  [1,6 >>> test_list.remove(1 >>>  [0,6 >>> test_list.insert(2, >>>  [0,6 >>> test_list.count( 2
 >>> 
 >>> test_list.count(  >>> test_list_extend = [,, >>> >>>  [0, >>> 
 >>>     File , 
      TypeError: unorderable types: str() < >>> test_list_extend.append( >>> test_lsit_extend.append(    File , 
     test_lsit_extend.append( NameError: name    >>> list_a = [,,, >>> >>>  [,, >>> (list_a.sort()) 
  >>> 
 >>> list_b = [1,4 >>>   >>>     File , 
      NameError: name    >>> 
 >>>  [1,6 >>> ( list_b[1  >>>  list_b[1 >>>  [1,6 >>>  list_b[0,2    File , 
      list_b[0,2 TypeError: list indices must be integers, >>>  list_b[0:2 >>>  [4,6 
 >>> 
 >>>  list_b[10    File , 
      list_b[10  >>> 
 >>> 
 >>> list_c = range(5 >>>  c       
     
  1
 2
 3
 4
 >>> list_d = >>>  d       
     
  1
 2
 3
 4
 >>> 
 >>> list_d[2] = 23
    File , 
     list_d[2] = 23
 TypeError:  object does  >>> list_e = [1,5 >>> list_f = >>> list_f[2] = 234
 >>>  [1,234,5 >>> 
 >>> 
 >>> 
 >>> 
 >>> 
 >>> list_i = >>>  [1,5 >>>  [1,5 >>> list_i[2] = 3
 >>>  [1,5 >>>  [1,5 >>> 
 >>> 
 >>> 
 >>> 

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读