<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 字符串與編碼 [TOC] * [參考資料](https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386819196283586a37629844456ca7e5a7faa9b94ee8000) >[info] #### 使用ord 字符轉ascii, chr將ascii轉字符 ~~~ print ord('a') 97 print chr(97) a ~~~ >[info] #### 中文輸出ascii和utf-8 ~~~ 輸出ASCII >>> u'中' 輸出utf-8編碼 >>>u'中'.encode('utf-8') >>>len(u'中') #計算長度 使用decode >>> print '\xe4\xb8\xad'.decode('utf-8') 中 ~~~ >[info] #### 格式化 使用% * %運算符就是用來格式化字符串的 * 有幾個%?占位符,后面就跟幾個變量或者值,順序要對應好。如果只有一個%?,括號可以省略 * %s 字符串 * %d 整數 * %f 浮點數 * %x 十六進制整數 ~~~ >>> 'my is %s' % 'wang' 'my is wang' >>> 'hi %s, you have $%d' % ('wang', 10) 'hi wang, you have $10' ~~~ * 其中,格式化整數和浮點數還可以指定是否補0和整數與小數的位數: ~~~ >>> '%2d-%02d' % (3, 1) ' 3-01' >>> '%.2f' % 3.1415926 '3.14' ~~~ * 對于Unicode字符串,用法完全一樣,但最好確保替換的字符串也是Unicode字符串: ~~~ >>> u'Hi, %s' % u'Michael' u'Hi, Michael' ~~~ * 有些時候,字符串里面的%是一個普通字符怎么辦?這個時候就需要轉義,用%%來表示一個%: ~~~ >>> 'growth rate: %d %%' % 7 'growth rate: 7 %' ~~~ >[warning] #### 文件的中文處理 * python 默認為ASCII碼,無法輸出漢字,需要更改編碼 ~~~ #coding=utf-8 或者 #coding=utf8 或 # -*- coding:UTF-8 -*- 或 # -*- coding:utf-8 -*- 大小寫忽略 寫成utf8或utf-8都行 ~~~ >[info] #### 多行語句 * 但是我們可以使用斜杠( \)將一行的語句分為多行顯示,如下所示: ~~~ total = item_one + \ item_two + \ item_three ~~~ * 語句中包含 [], {} 或 () 括號就不需要使用多行連接符。如下實例: ~~~ days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'] ~~~ >[info] #### 同一行顯示多條語句 * Python可以在同一行中使用多條語句,語句之間使用分號(;)分割,以下是一個簡單的實例: ~~~ #!/usr/bin/python import sys; x = 'runoob'; sys.stdout.write(x + '\n') ~~~ >[warning] #### Python空行 * 記住:空行也是程序代碼的一部分 >[info] #### Print 輸出 * print 默認輸出是換行的,如果要實現不換行需要在變量末尾加上逗號 , ~~~ #!/usr/bin/python # -*- coding: UTF-8 -*- x="a" y="b" # 換行輸出 print x print y print '---------' # 不換行輸出 print x, print y, # 不換行輸出 print x,y ~~~
                  <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>

                              哎呀哎呀视频在线观看