python 內建函數

來源:互聯網
上載者:User

標籤:class   obj   new   進度   表示   orm   購物   內建函數   log   

一  print( )

  flush的應用——類比進度條

import timefor i in range(1,101):    time.sleep(0.1)    print(‘\r{}%:{}‘.format(i,‘*‘*i),end=‘‘,flush=True)           #\r (return) 表示斷行符號  \n (new line)表示換行,實際上是斷行符號換行print()print(‘END!‘)

二 hash( )

  1 參數必須是不可變類型。

print(hash(‘aaa‘))print(hash(b‘aaa‘))print(hash(‘123‘))print(hash(b‘123‘))print(hash(123))print(hash(True))print(hash(False))

  輸入:

-4644624363813443981-46446243638134439817614025369805395482761402536980539548212310

 三  map( ) 映射  內建遍曆可迭代對象功能

 四  filter( ) 過濾  內建遍曆可迭代對象功能

 五  enumerate() 函數用於將一個可遍曆的資料對象(如列表、元組或字串)組合為一個索引序列,同時列出資料和資料下標,一般用在 for 迴圈當中。

  用處:購物車

goods={‘computer‘:1000,‘umbrella‘:200}e=enumerate(goods,1)print(e)for num,name in e:    print(num,name,goods[name])

  輸出:  

<enumerate object at 0x000001C6FDCA85E8>1 computer 10002 umbrella 200

 

  

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.