week02_python內建資料結構__01

來源:互聯網
上載者:User

標籤:函數   數值   記憶體地區   max   轉換   2.4   傳回值   port   字元   

數值型
  • > 數值型:

    int、float、complex、bool都是class,1,5.0,2+3j都是對象即執行個體;
    int:python3的int就是長整型,且沒有大小限制,受限於記憶體地區的大小;
    float:額整數部分和小數部分組成。支援十進位和科學計數法表示。只有雙精確度型 。
    complex:有實數和虛數部分組成,實數和虛數部分都是浮點數,3+4.2j
    bool:int的子類,僅有2個執行個體True、False對應1和0,可以和整數直接運算

  • > 類型轉換(built-in)

    int(x) 返回一個整數
    float(x) 返回一個浮點數
    complex(x)、complex(x, y) 返回一個複數
    bool(x) 返回布爾值,前面講過False等價的對象

數位處理函數

round() :四捨六入,五取偶
floor():向下取整
ceil():向上取整
int():取整數部分,和//整除一樣

  • > 舉例:

    import math
    print(math.floor(2.5))
    print(math.ceil(2.5))
    print(round(2.51))
    print(round(2.5))
    print(round(2.4))

min()
max()
pow(x,y) 等於x**y
math.sqrt()

  • > 進位函數,傳回值是字串

    bin()
    oct()
    hex()

math.pi 派
math.e自如常數

類型判斷

type(obj),傳回型別,而不是字串
isinstance(obj,class_or_tuple),返回布爾值

  • > 舉例:

    type(a)
    type(‘abc‘)
    type(123)
    isinstance(6,str)
    isinstance(6,(str,bool,int))

    type(1+True)

week02_python內建資料結構__01

聯繫我們

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