<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 字符串常見操作 如有字符串`mystr = 'hello world itcast and itcastcpp'`,以下是常見的操作 #### 1\. find 檢測 str 是否包含在 mystr中,如果是返回開始的索引值,否則返回-1 ~~~ mystr.find(str, start=0, end=len(mystr)) ~~~ ![](https://img.kancloud.cn/9a/f2/9af2c9b715c14fd032dfa77e11c4aec4_708x112.png) ![](https://img.kancloud.cn/c9/41/c941decc09766f1984dcef57eff8618f_714x111.png) #### 2\. index 跟find()方法一樣,只不過如果str不在 mystr中會報一個異常. ~~~ mystr.index(str, start=0, end=len(mystr)) ~~~ ![](https://img.kancloud.cn/eb/d1/ebd106c734595c22489c8cc01ae6ec80_710x235.png) #### 3\. count 返回 str在start和end之間 在 mystr里面出現的次數 ~~~ mystr.count(str, start=0, end=len(mystr)) ~~~ ![](https://img.kancloud.cn/6e/2b/6e2b727d8a3b2e1e66d7af1121f580ab_740x113.png) #### 4\. replace 把 mystr 中的 str1 替換成 str2,如果 count 指定,則替換不超過 count 次. ~~~ mystr.replace(str1, str2, mystr.count(str1)) ~~~ ![](https://img.kancloud.cn/fa/69/fa69d208c157358cb0f108e5df484704_508x179.png) #### 5\. split 以 str 為分隔符切片 mystr,如果 maxsplit有指定值,則僅分隔 maxsplit 個子字符串 ~~~ mystr.split(str=" ", 2) ~~~ ![](https://img.kancloud.cn/f9/20/f9204d7a74772dcaf2f12c310a814b5d_534x178.png) #### 6\. capitalize 把字符串的第一個字符大寫 ~~~ mystr.capitalize() ~~~ ![](https://img.kancloud.cn/21/ce/21ceff8a94bb3b1f5bd7d7f03612c8a6_744x119.png) #### 7\. title 把字符串的每個單詞首字母大寫 ~~~ >>> a = "hello itcast" >>> a.title() 'Hello Itcast' ~~~ #### 8\. startswith 檢查字符串是否是以 hello 開頭, 是則返回 True,否則返回 False ~~~ mystr.startswith(hello) ~~~ ![](https://img.kancloud.cn/2c/13/2c130348d7e75ddefcee21ac4ed636c8_797x176.png) #### 9\. endswith 檢查字符串是否以obj結束,如果是返回True,否則返回 False. ~~~ mystr.endswith(obj) ~~~ ![](https://img.kancloud.cn/64/2f/642f3410b357731dde23ee880ab4bb7e_725x172.png) #### 10\. lower 轉換 mystr 中所有大寫字符為小寫 ~~~ mystr.lower() ~~~ ![](https://img.kancloud.cn/3d/30/3d303bb4a5ca4b1d0afb9594e66a900f_717x119.png) #### 11\. upper 轉換 mystr 中的小寫字母為大寫 ~~~ mystr.upper() ~~~ ![](https://img.kancloud.cn/0c/c6/0cc6cebd255a237ffcc69dbadf1b5c8a_731x122.png) #### 12\. lstrip 刪除 mystr 左邊的空白字符 ~~~ mystr.lstrip() ~~~ ![](https://img.kancloud.cn/d7/b6/d7b6c934926e90493dec4c940c5418b4_546x206.png) #### 13\. rstrip 刪除 mystr 字符串末尾的空白字符 ~~~ mystr.rstrip() ~~~ ![](https://img.kancloud.cn/e2/d8/e2d8c39b6c22bee4f59c3c53933c375c_548x114.png) #### 14\. strip 刪除mystr字符串兩端的空白字符 ~~~ >>> a = "\n\t itcast \t\n" >>> a.strip() 'itcast' ~~~ ### 15\. rfind 類似于 find()函數,不過是從右邊開始查找. ~~~ mystr.rfind(str, start=0,end=len(mystr) ) ~~~ ![](https://img.kancloud.cn/39/00/3900c54f64bb4215b46f4de373d4ea48_683x117.png) ### 16\. rindex 類似于 index(),不過是從右邊開始. ~~~ mystr.rindex( str, start=0,end=len(mystr)) ~~~ ![](https://img.kancloud.cn/50/7c/507cb67f678c85f203d8b12389987b46_727x175.png) ### 17\. partition 把mystr以str分割成三部分,str前,str和str后 ~~~ mystr.partition(str) ~~~ ![](https://img.kancloud.cn/55/cf/55cf2c90eae6ae682c6940a001fab44e_745x116.png) ### 18\. rpartition 類似于 partition()函數,不過是從右邊開始. ~~~ mystr.rpartition(str) ~~~ ![](https://img.kancloud.cn/fb/aa/fbaa358fba1687d962b70db50e6feccf_757x183.png) ### 19\. splitlines 按照行分隔,返回一個包含各行作為元素的列表 ~~~ mystr.splitlines() ~~~ ![](https://img.kancloud.cn/ce/27/ce2756bf9aa7dc526f5e21d94414f1a1_507x202.png) ### 20\. isalpha 如果 mystr 所有字符都是字母 則返回 True,否則返回 False ~~~ mystr.isalpha() ~~~ ![](https://img.kancloud.cn/41/0c/410cc5d71c7d15dfb9745422cf9b974f_367x291.png) ### 21\. isdigit 如果 mystr 只包含數字則返回 True 否則返回 False. ~~~ mystr.isdigit() ~~~ ![](https://img.kancloud.cn/3d/f1/3df1dc0727fa6c9f5dbe48b6c7d58936_398x297.png) ### 22\. isalnum 如果 mystr 所有字符都是字母或數字則返回 True,否則返回 False ~~~ mystr.isalnum() ~~~ ![](https://img.kancloud.cn/c2/aa/c2aa4f043ba7fc1b1a5aea69ab64f8c0_431x385.png) ### 23\. isspace 如果 mystr 中只包含空格,則返回 True,否則返回 False. ~~~ mystr.isspace() ~~~ ![](https://img.kancloud.cn/be/68/be68fcf08942f73c3baac48017b728cf_390x382.png) ### 24\. join mystr 中每個元素后面插入str,構造出一個新的字符串 ~~~ mystr.join(str) ~~~ ![](https://img.kancloud.cn/d1/98/d19841ea3ade0731441f513dd9f81c2a_609x235.png) # 想一想 * (面試題)給定一個字符串aStr,返回使用空格或者'\\t'分割后的倒數第二個子串 ![![](../Images/Snip20161225_1.png)](images/screenshot_1593859329967.png)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看