自學Python全棧開發第四次筆記(Python常用資料類型,字串)

來源:互聯網
上載者:User

標籤:位置   bool   不能   fill   new   cas   基本   wap   解釋   

今天開始學Python常用資料類型了。基礎資料型別 (Elementary Data Type);數字                int字串            str布爾值            bool列表                list元組                tuple字典                dict 所有字串或者數字,字典,所具備的方法存在相對應的“值“裡      按Ctrl+左擊顯示 模板是類(int,str,bool......)模板建立不是值是對象關係:所有對象所具備的功能都存在相對應的類。  
  1. 查看對象的類或對象所具備的功能
          a.通過type          temp = "alex"          t = type(temp)          print(t)###如果顯示str,Ctrl+左擊找到str類,內部所有方法
  1. temp = "alex"
          b= dir(temp)
  1. 通過help,type
  2. 直接點擊
            temp = "alex"            temp.upper()滑鼠放在upper上,Ctrl+左擊,自動定位到upper功能解釋    ret = n1()            沒有參數ret = n1(2)          傳了一個參數ret = n1(2,abc,caa)       傳了三個參數  self            表示不用傳參數self,with,fill    最多傳兩個參數self star = None    預設有值(可傳可不傳)      基礎資料型別 (Elementary Data Type)常用功能:
  1. 整數 int
         a.            #n1= 123            #n2 = 456            #print(n1+n2)            #print(n1._add_n2)        b.            擷取可表示二進位最短位元            n1 = 4   #000000/00            ret = n1.bit_length()            print(ret) 
  1. 首字母變大寫 capitalize(self)
            a1 = "qiao"             ret = a1.capitalize()            print(ret)            ###列印Qiao  
  1. center(self,width,fillchar=None)
        """內容置中,width:總長度;fillchar:空白處填充內容預設無"""            a1 = "qiao"            net = a1.center(20,‘*‘)            print(ret)            ###列印--------qiao--------
  1. count(self,sub,star=None,end=None)
            """子序列個數"""            a1 = "qiao"            ret = a1.count("a")            print(ret)                                                            /ret = a1.count("a",0,3)       0 = q       1 = i       2 = a            ###列印1(a有1次出現)
  1. endswith(self,suffix,start=None,end=None)                              
            """是否以xxx結束"""            a1 = "qiao"            ret = a1.endswith("0")                                       擷取字元中大於0小於2的位置            print(ret)                                                           /ret = a1.endswith("0",0,2)            ###列印Ture/False    
  1. expandtabs(self,tabsize = None)
            """將Tab轉換成空格,預設一個Tab轉換成8個空格"""            content = "hello\tqqq"            print(content)            print(content.expandtabs())            print(content,expandtabs(20))            ###hello    999                  hello    999                  hello                        999
  1. find(self,sub,star = None,end = None)
            """尋找子序列位置,如果沒找到返回-1"""            s = "qiao hello"            print(s.find("ao"))            ###列印2(從前開始向後找,找到第一個)若找不到顯示"-1"
  1. format(*args,**kwargs)
            """字串格式化,動態參數"""            s = "hello{0},age{1}"            print(s)            #{0}預留位置            new = s.format("qiao",19)            print(new1)            ###列印hello{0},age{1}                  hello qiao,age19
  1. join(self,iterable)
            """串連"""            li = ["qiao","wang"]      #列表[ ]        (  )元組            s = "_".join(li)            print(s)            ###列印qiao_wang
  1. lstrip(self,chars = None)    rstrip(移除右側空白)          strip(左右兩邊都去掉)
            """移除左側空白"""            s = "qiao"            news = s.lstrip()            print(news)            ###列印qiao...            ...qiao
  1. partition(self,sep)
            """分割,前,中,後三部分"""            s = "alex SB alex"            ret = s.partition("SB")            print(ret)            ###列印(‘alex‘,‘SB‘,‘alex‘)      元群組類型
  1. replace(self,old,new,count = None)
            """替換"""            s = "alex SB alex"            ret = s.replace("al","bb")              ("al","bb",從左向右第一個)            print(ret)            ###列印bbex SB bbex
  1. rstip(self,chars = None)
            """分割"""            s = "alexalex"            ret = s.split("e")             ("e",1)            print(ret)            ###列印[‘al‘,‘xal‘‘x‘]
  1. swapcase(self)
            """大寫變小寫,小寫變大寫"""            s = Qiao            print(s.swapcase())            ###列印qIAO
  1. title(self)
            """轉換標題"""            s = "the school"            ret = s.title()            print(ret)            ###列印TheSchool索引s = "alex"print(s[0])print(s[1])print(s[2])print(s[3])###列印alex   長度s = "alex"ret = len(s)print(ret)###列印4(有4位,從0開始)  切片s = "alex"print(s[0:2])            >=0   <2   (0,1)###列印al    for迴圈,break,continue可以引用s = "alex"for item in s :    print(item)          (item是變數名)###列印alex                        continues = "alex"for item in s :    if item == "l"        continue   print(item)###列印aex                        breaks = "alex"for item in s :    if item == "l"        break    print(item)###列印a   for item in s :          (item是變數名,隨意)(s是要迴圈的東西)終於整理完了。好累,腰酸背痛。以後不能把知識積累這麼多再整理blog了,一定要及時整理,晚安。

自學Python全棧開發第四次筆記(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.