Python之內建函數

來源:互聯網
上載者:User

標籤:instance   col   lex   als   []   bytes   Oz   布爾   類型   

Python之內建函數

  abs( ) 求絕對值。

    小於零的數,變為大於零的數。

# print(abs(-1))# print(abs(0))

  all( )  只要可迭代對象為空白,即可返回結果為True。

      迭代對象不為空白時,所有的對象做布爾值運算,全為True是,為True,否則為False。

# print(all(‘ ‘))# print(all((1,‘ ‘,2,None)))# print(all(i for i in range(1,10)))

  sum( ) 求和函數

# res=sum(i for i in range(3))# print(res)

  any( ) 可迭代對象為空白時,返回False。

      可迭代對象中的任何一個結果的布爾值為True,則全為True。

# print(any([]))# print(any([None,0,‘‘,{},1]))

  ascii( )

  bin( ) 將一個數轉成二進位。

# print(bin(3))

  bool( )  判斷布爾值。

# print(bool(0))# print(bool(None))# print(bool(‘‘))

  bytes( ) 把字串轉成位元組形似。

# print(bytes(‘hello‘,encoding=‘utf-8‘))

  callable( ) 是否可以調用。返回布爾值。

# def test():#     pass# print(callable(test))# print(callable(sum))

  chr( ) 是ASCII碼的轉換關係,數字對應ASCII碼錶的相應的位置字元

# print(chr(67))# print(chr(65))

  ord( ) 是ASCII碼的轉換關係  字元對應ASCII碼錶的相應的位置數字

# print(ord(‘A‘))

  資料類型: 

#資料類型#int# num=1 #num=int(1)  # print(type(num)) #查看num的類型# print(isinstance(num,int)) #判斷num是否為int類型# print(num is 1) #is 是身份運算,根據id去判斷身份# float# bool# complex# str# x=‘asdfa‘ #x=str(‘asdfa‘)# print(str(1))# print(str({‘a‘:1}))# list# x=[]# x=list(i for i in range(10))# print(x)# tuple# dict# d={‘a‘:1}# d=dict(x=1,y=2,z=3)# print(d)set# s={1,2,3,4,4}# print(s)# s.add(5)# print(s)## frozenset #不可變集合# f=frozenset({1,2,3,4})# print(type(f))# x=complex(1-2j)# print(x.real)# print(x.imag)# x=1-2j# print(x.real)# print(x.imag)

 

  

 

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.