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

來源:互聯網
上載者:User

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

基礎資料型別 (Elementary Data Type)常用功能:

  1、整數(int)

  • bit_length(self)    #擷取可表示的二進位最短位元
  • +、- 
x = 4
print(x.bit_length())


2.字串(str)
  • center #置中 格式:a1.center(20.'*')
  • count #字串中子序列的出現的次數 格式:a1.count("ab",0,4) 或 a1.count("ab")
  • endswith #是否以ab結尾,返回結果True或Fales 格式:a1.endswith('ab',0,4) 或 a1.endswith('ab')
  • startswith
  • expandtabs #把Tab鍵(\t)轉換成空格鍵,預設轉換成8個空格
  • find #尋找,返回所在位置。沒找到返回-1
  • rfind
  • format #把字串中的預留位置({0},{1}····)轉換成設定值
  • join  #串連     把字串用*串連  格式:"***".join(a1)
  • ljust  #內容靠左對齊,右側填充,類似center       格式:a1.ljust(30,'*')
  • rjust
  • lower #變小寫
  • lstrip  #移除左邊的空格
  • rstrip #移除右邊的空格
  • strip #移除兩邊的空格
  • partition # 分割,前、中、後三部分,返回結果為元群組類型。 格式:a1.partition('ab')
  • rpartiton
  • replace  #替換   格式:a1.replace("ab","cc",1)   從左向右第一個ab換成cc
  • split  #分割   格式:split(‘e’,1)
  • rsplit 
  • swapcase  #大小寫轉換
  • title #標題
  • upper

索引

  a1[0]

  a1[1]

  len(a1)  #長度

切片

  a1[0:2]

迴圈

  while i < len(s):

    a2=a1[i]

  或

  for i in a1:

    print(i)

3.列表(list)

索引

切片

for迴圈

  • append   #追加   格式:list1.append("abcd")
  • count     #統計個數  格式:list1.count("abcd")
  • iterable #可迭代的

聯繫我們

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