python基礎資料型別 (Elementary Data Type)

來源:互聯網
上載者:User

標籤:image   自動   等於   api   整數   傳參數   center   定位   dict   

在python中的基礎資料型別 (Elementary Data Type)有:int(數字) str(字串) bool(布爾值) list(列表) tupel(元組) dict(字典)

類與對象的關係

如何查看對象的類?通過type來擷取類型

temp = "hey"print(type(temp))

輸出為:<class ‘str‘>

如何在pycharm中查看類和對象的具體功能?

方法1:str,ctr+滑鼠左鍵,找到str類,查看內部的方法。

方法2:B=dir(temp)

方法3:通過help

help(type(temp))

方法4:直接點擊方法,滑鼠放在方法上 ctr+滑鼠左鍵 會自動定位到功能處。

 

基礎資料型別 (Elementary Data Type):int

n1 = 123n2 = 456print(n1+n2)

n1 = 123n2 = 456print(n1.__add__(n2))

是一樣的。底線的方法都是內建的。

 

查看二進位的位元:

n1 = 4ret = n1.bit_length()print(ret)

輸出結果是3,說明二進位的位元是3

方法center:

a1 = "alex"ret = a1.center(20,‘_‘)

輸出為

count方法:

a1 = "alex is alph"ret = a1.count(‘a1‘,0)print(ret)

輸出為:

 

 endswitch擷取字串裡面大於等於0的位置小於2的位置:

temp = "hello"print (temp.endswitch(‘e‘,0,2)
content = "hello\t999"print(content)print(content.expandtabs())print(content.enpandtabs(20))

 

s = "hello {0}, age {1}"print(s)new1 = s.format(‘alex‘,19)print(new1)

{0}{1}預留位置

 

在如下查看源碼說明的時候,看到例如def capitalize(self)裡面有self的方法,表示不用傳參數,否則要在括弧內寫入參數。

如果有xxx = None 表示預設參數,如果不傳就是none,可以傳也可以不傳

1、數字

int(整型)

  在32位機器上,整數的位元為32位,取值範圍為-2**31~2**31-1,即-2147483648~2147483647
  在64位系統上,整數的位元為64位,取值範圍為-2**63~2**63-1,即-9223372036854775808~9223372036854775807

int裡面重要的方法

int
2、布爾值  真或假  1 或 0 3、字串
"hello world"
字串常用功能:
  • 移除空白
  • 分割
  • 長度
  • 索引
  • 切片

str重要的方法

str

 

python基礎資料型別 (Elementary Data Type)

聯繫我們

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