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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] 這篇文章主要介紹了python3中bytes和string之間的互相轉換,文中給出了詳細的介紹和示例代碼,相信對大家具有一定的參考價值,有需要的朋友們下面來一起學習學習吧。 **前言** Python 3最重要的新特性大概要算是對文本和二進制數據作了更為清晰的區分。文本總是Unicode,由str類型表示,二進制數據則由bytes類型表示。Python 3不會以任意隱式的方式混用str和bytes,正是這使得兩者的區分特別清晰。你不能拼接字符串和字節包,也無法在字節包里搜索字符串(反之亦然),也不能將字符串傳入參數為字節包的函數(反之亦然). **python3.0中怎么創建bytes型數據** bytes([1,2,3,4,5,6,7,8,9]) bytes("python", 'ascii') # 字符串,編碼 **首先來設置一個原始的字符串,** Python 3.2.3 (default, Apr 11 2012, 07:15:24) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> website = 'http://www.jb51.net/' >>> type(website) >>> website 'http://www.jb51.net/' >>> **按utf-8的方式編碼,轉成bytes** >>> website_bytes_utf8 = website.encode(encoding="utf-8") >>> type(website_bytes_utf8) >>> website_bytes_utf8 b'http://www.jb51.net/' >>> **按gb2312的方式編碼,轉成bytes** >>> website_bytes_gb2312 = website.encode(encoding="gb2312") >>> type(website_bytes_gb2312) >>> website_bytes_gb2312 b'http://www.jb51.net/' >>> **解碼成string,默認不填** >>> website_string = website_bytes_utf8.decode() >>> type(website_string) >>> website_string 'http://www.jb51.net/' >>> >>> **解碼成string,使用gb2312的方式** >>> website_string_gb2312 = website_bytes_gb2312.decode("gb2312") >>> type(website_string_gb2312) >>> website_string_gb2312 'http://www.jb51.net/' >>> **總結** 以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
                  <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>

                              哎呀哎呀视频在线观看