<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                1、capitalize 首字母大寫 test = "alex" #首字母大寫 v = test.capitalize() print(v) 結果: Alex 2、大小寫轉換 2.1)大寫字母轉換成小寫 lower casefold(很多未知的都能變小寫,一般用不到) ![](https://box.kancloud.cn/afcf3b92cb1e46c3da3dc35a2a6628b2_767x217.png) 3、center 功能:設置這個字符占的寬度 #def center(width,fillchar=None) 遇到=,可以帶,可以不帶 #設置寬度,并將內容居中 # width 20 代表總長度 # * 空白位置填充,只能帶一個字符,也可以不填寫 test = "ALEX" v1 = test.center(20,"*") print(v1) 類似: ljust: 放左邊 rjust:放右邊 ![](https://box.kancloud.cn/fbcb592edc4bf7838c818940ae7da183_766x129.png) 4、count 功能: 判斷這個字母出現的次數 #def count(self, sub, start=None, end=None) #start 表示從第幾位開始 #end 表示找到第幾位結束 #默認是所有的,從第一位開始找 test = "louisalexfix" v1 = test.count('l') print(v1) test = "loexuiexlexfix" v1 = test.count('ex',5,10) print(v1) 4、endswith 功能:以()里的結尾, 可以用于條件判斷 ![](https://box.kancloud.cn/780536051fdc5aa94016c91fd5082ca4_999x448.png) 5、startswith 功能: 以()里的開頭,可以用于條件判斷 ![](https://box.kancloud.cn/19655a33bf470cdc33a25438efa2d248_894x422.png) 6、find 功能: 從前往后查找,找到第一個,獲取其位置,之后的就不查找咯。不能找到顯示-1 test = "alexalexfiex" v1 = test.find('ex') print(v1) 結果: 2 ![](https://box.kancloud.cn/001c6fb2d804f6ddca2861de04200c55_776x218.png) 7、format 功能: 格式化,將字符串上的占位符,替換成指定的值 ![](https://box.kancloud.cn/362f1b8d6651b9b52f68924293d5509a_785x120.png) ![](https://box.kancloud.cn/39d8a9e79794102e53bb46dcc4647508_780x114.png) ![](https://box.kancloud.cn/bb039d9292973777210bfffea6ce87c9_525x114.png)--format_map name = input("please input name:") age = input("please input age: ") tem="I am {0},age {1}" v1 = tem.format(name,age) print(v1) 8:判斷是否是啥 ---可以用于條件判斷 8.1)isalum 字符串里只能出現字母和數字 ![](https://box.kancloud.cn/c7d2665a33f2700fdd5771107d43b6d4_946x218.png) 8.2) isalpha 判斷是否為字母、漢子 test = "我" v1 = test.isalpha() print(v1) ![](https://box.kancloud.cn/1be35e66092c5d7e7175e4af3bceff16_846x220.png) 8.3) isdigit 功能:判斷當前是不是數字 ![](https://box.kancloud.cn/d2b924ecb4ee7956c5a5ce37c2667f07_863x128.png) 相似的: isnumeric 支持中文的數字,比如二 isdecimal 支持特殊的字符2 案例: ![](https://box.kancloud.cn/8ea46408c73c3b111b920b22239b9c6d_848x296.png) 注意: 以后用的最多的,還是isdecimal比較多 8.4) isidentifier 功能:判斷是否有一個標識符,需要滿足有字母,數字,下劃線 以數字開頭的,都為false ![](https://box.kancloud.cn/900c2b6b4dd9a334f9e228327adf3038_1008x344.png) ![](https://box.kancloud.cn/ce43103c1fe782746c358a713c9aecf2_817x337.png) 8.5) isspace 功能:是否為空格 ![](https://box.kancloud.cn/515e63549420a69bb9620a9f2ad4e835_781x321.png) 8.6) islower lower 功能: 判斷是否全部為小寫字母和轉換為小寫 ![](https://box.kancloud.cn/de9c7e4182cd6d9429f175e3d34a603a_413x111.png) 8.7) isupper supper 功能:判斷是否全部為大寫,和轉換給大寫 ![](https://box.kancloud.cn/4a2391ea566b91752d5046c2bcac6516_522x119.png) 9: expandtabs 功能:分隔,對齊 expandtabs(n),以n個為一組,如果遇到\t, 就以空格補全 test="abcdeffd\tdif\tdi\t" v1 = test.expandtabs(6) print(v1) 原理: abcdef fd\t dif\t di\t 遇到\t,把不夠的用空格標識,例如這里是6,然后fd只占有2個,遇到\t咯,那么就需要補4個空格,依次類推 ![](https://box.kancloud.cn/5cf2584f45b318f6f967c994074a8202_945x155.png) 10 join -------非常重要 功能:#將字符串中的每一個元素按照指定的分隔符分開 test = "你是風兒我是沙" v1 = "_".join(test) print(v1) 11、lstrip rstrip strip 功能: 1)去掉空白 2)去掉\n,\t特殊的字符 3)去掉指定的字符,以先最多匹配去除,依次去找 lstrip: 取出左邊的 rstrip: 取出右邊的 strip: 取出左右兩邊 ![](https://box.kancloud.cn/d9b970421427c2b13d56b227f93a87d7_741x476.png) ![](https://box.kancloud.cn/b9949c991975ff3f1e7404df823a2e91_793x203.png) 12、partition 功能: 以某個()東西為分隔,只能分隔成三分 split: 匹配到的字符拿不到 可以指定分隔的個數 默認是全部 ![](https://box.kancloud.cn/0112d3f1b26d07aff6a22ee974b08767_833x487.png) 13、字符串替換replace ![](https://box.kancloud.cn/c9af9a256b39609108ac97d6cb8fb5bf_828x308.png) 重點: join 連接 split(split,lspit,rspit)分隔 find (查找) strip(lstrip,rstrip,strip)去除 upper 大寫 lower 小寫 replace 替換 #########################灰魔法####################### 1、獲取字符串里的某一個字符,索引從0開始 ![](https://box.kancloud.cn/b994182c769c205dfa4b3efff7833612_663x212.png) 2、切片, 左邊 <=x < 右邊 ![](https://box.kancloud.cn/4011afb0bc09b4437a0ee60789275e77_832x385.png) 3、len test = "我來自云南省昆明市" index = 0 while index < len(test): t = test[index] print(t) index += 1 test = "我來自云南省昆明市" # for index in test: print(index) 4、循環(for,while) test = "thisidfswork" v1 = test.split('s') for i in v1: print(i) ![](https://box.kancloud.cn/96e7b5bef4c75b090c96520d576fc8f5_802x155.png) 5、range 功能:幫助創建連續的數字,默認從0開始,也可以創建不連續的數字 在python2中會直接創建,在python3中,要用循環,才會打印出來 ![](https://box.kancloud.cn/017730c36f6154bf391944a3aa92c307_746x225.png) ![](https://box.kancloud.cn/4067ad7f3cd3798dfbe5523247de4568_919x380.png) test = input("please input: ") len = len(test) for item in range(0,len): print(item,test[item]) 案例:打印一個表格 test = " " while True: t = input("please input caozhuo: ") if t == "y": name = input("please input name: ") pwd = input("please input passwd: ") email = input("please input email adddress: ") temp = "{0}\t{1}\t{2}\n" v1 = temp.format(name,pwd,email) test = test + v1 elif t == "q": break else: pass print(test.expandtabs(20)) ![](https://box.kancloud.cn/4f2872fa8d6a09f046f66487c0ae9770_796x432.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>

                              哎呀哎呀视频在线观看