python---序列可使用的內建函數(BIFs)

來源:互聯網
上載者:User

標籤:

python序列可使用的內建函數

  1. enumerate(iter)

    接受一個可迭代對象為為參數,返回一個enumerate(遍曆)對象。

    #!/usr/bin/env python #-_- coding: utf-8 -_-

     

    #enumerate(iter)函數返回由index(索引)和item值組成的元祖,元祖數量由iter可迭代對象的元素決定。 def Enumerate(name): for Index, Name in enumerate(name):   print("%d  %s" %(Index, Name))

    name = [‘John‘, ‘Jimmy‘, ‘Tom‘, ‘Kate‘] Enumerate(name)

  2. len(seq) 返回seq的長度

  3. max(iter)

    max(arg0,arg1, ... key=None)

  4. min(iter)

    min(arg0,arg1, ... key=None)

  5. reversed(seq)

    接受一個序列作為參數,返回一個以逆序訪問的迭代器。

     

  6. sorted(iter,func=None,key=None,reverse=False)

    接受一個可迭代對象作為參數,返回一個有序的列表;選擇性參數func,key 和reverse 的含義跟list.sort()內建函數的參數含義一樣。

  7. sum(seq, int=0)

    返回seq 和選擇性參數init 的總和, 其效果等同於reduce(operator.add,seq,init)

     

  8. zip([it0, it1, ... itN])

    zip(seq1 [, seq2 [...]]) -> [(seq1[0], seq2[0] ...), (...)]                         

        Return a list of tuples, where each tuple contains the i-th element from each of the argument sequences.  The returned list is truncated in length to the length of the shortest argument sequence.

python---序列可使用的內建函數(BIFs)

相關文章

聯繫我們

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