[Day4]-基本串列(list)

  • 串列基本定义
  1. 串列可以储存不同的资料型态,如:整数、字串、浮点数,基本格式如下:
    List = [元素1,元素2…..]
    元素1 = List[0]
    元素2 = List[1]
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644lLP2g3abbM.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644McJAligG8z.png

  2. 串列切片
    List[a:b] – 读取索引a到b-a个索引元素
    List[:a] – 读取从索引0到索引a-1的每个元素
    List[:-a] – 读取从头的元素,但不含最後a个
    List[a:] – 读取从索引a开始到最後的元素
    List[-a:] – 读取後面a个元素
    List[:] – 读取所有的元素
    List[a:b:c] – 每隔c,读取索引a到b-a个索引元素
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644uAqd6B0RTV.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644JsjLnGveZy.png

  3. 更改、增加及删除元素内容

  • 更改
    https://ithelp.ithome.com.tw/upload/images/20210916/201406448THh0DXxLc.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644poY76swUoN.png

  • 增加
    List.append(‘新增元素’) 固定加在最後面
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644XVAHCFz8jT.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644XjE53u9810.png
    List.insert(n,元素内容) 加在n+1的位子
    https://ithelp.ithome.com.tw/upload/images/20210916/201406442A8s5gEftu.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644wCSIuAXKk2.png

  • 删除
    del list[n] 删除第n+1的元素
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644sYO4N6nuhh.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644boY6ssFcoy.png
    Pop_list = list.pop() 删除最後一个元素
    Pop_list = list.pop(n) 删除第n+1个元素
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644MJlkUp8rsr.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644IqqZSnXHo5.png
    List.remove(删除的元素内容)
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644bNmY3lvqSn.png
    https://ithelp.ithome.com.tw/upload/images/20210916/20140644CemOJghl8u.png


<<:  Day 0xF UVa10071 Back to High School Physics

>>:  Vue.js 从零开始:MVVM、渐进式框架

JavaScript学习日记 : Day6 - 函数(一)

1.函数的重要性 因为函数是Javascript世界的第一等公民,指的是函数与其他数据类型一样,处於...

[Day 30] 资料产品开发实务 - 完结撒花!

终於撑完三十天啦啊啊啊啊!!!没想到自己有一天也能完成这个壮举(拭泪),真的太敬佩各路大神以及前辈了...

[Python]使用Pillow,将图片由RGB转灰阶(Grayscale)

RGB -> Gray scale Gray scale(灰阶影像) from PIL imp...

Day26 D3js 浪漫复刻ExpertOption的养眼图表

D3js 浪漫复刻ExpertOption的养眼图表 用途 在以往实现d3图表时,多半是功能优先,可...