【Python】【序列】

來源:互聯網
上載者:User

標籤:amp   使用   from   pen   bytes   傳參數   python   append   import   

1. array

1?? 和list

首先引入

from array import array

然後list到array直接傳參數進建構函式就可以。(不知道是不是叫建構函式)

np.array(‘d‘,[1,2,3])

轉回來的話調用tolist函數

_.tolist()

2??枚舉&常用方法

array使用方法:
Type code   C Type             Minimum size in bytes
        ‘c‘         character                       1
        ‘b‘         signed integer              1
        ‘B‘         unsigned integer        1
        ‘u‘         Unicode character       2
        ‘h‘         signed integer            2
        ‘H‘         unsigned integer         2
        ‘i‘         signed integer            2
        ‘I‘         unsigned integer         2
        ‘l‘         signed integer            4
        ‘L‘         unsigned integer         4
        ‘f‘         floating point              4
        ‘d‘         floating point              8
from array import *
建立一個interger類型的數組
myarr = array("l")  <--------建立數組
myarr.append(3)  <----------------追加元素
myarr.append(1)
myarr.append(8)

刪除最後一個
myarr.pop()
刪除第一個指定的X
myarr.remove(x)

取數組的值。。。。。通過下標
num1 = myarr[0]   <-----------第一個值

指定位置,。。。。插入值   

myarr.insert(6,10)  6表示下標。。。。10表示要插入的值


數組反序。。。。。
myarr.reverse()

 

【Python】【序列】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.