Python-序列-str list tuple

來源:互聯網
上載者:User

標籤:asc   font   [1]   拷貝   microsoft   class   長度   切片   pytho   

序列 有序數列
  str tupe list
  str tupe 不可變
  list 可變

序列(str list tuple) 每個元素都會有個序號(0開始計數)
  1. 知索引取單個確定類型 [index]
  2. 知值取索引.index
  3. 切片 [start: end: step], 負數(-1開始計數)從序列倒數第幾個取值,空表示從左至右取到最後
  4. 取序列的長度 len
  5. 求數列中最大最小 max min非數字類型轉化為ascii碼對應的數字進行比較
  6. 序列求和 sum
  7. 序列拼接+
  8. 序列拷貝次數 *
  9. 統計元素.count
  10. 刪除 del

str_list = ["hai", "hello", "wei", "here", 1, 2, 3]print(str_list[1])print(str_list.index("hai"))print(str_list[:1])print(str_list[::2])print(len(str_list))print(max(str_list[:4]))print(min(str_list[4:]))print(sum(str_list[4:]))print(str_list + [8, "aliYun"])print(str_list * 2)print(str_list.count("hai"))del str_list[0]print(str_list)

 

判斷單個元素是否在這個序列中
  1. 是否在 in
  2. 是否不在 not in

str_elements = "sjidanntlsnakn "print(" " in str_elements)print("sji" not in str_elements)

 

  

 

Python-序列-str list tuple

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.