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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### 6.2.3 元組 第 2 章中簡單介紹了元組數據類型,我們知道元組是用一對圓括號括起、用逗號分隔的多個數據項的集合體。元組也是序列的一種,可以利用表 6.1 中的序列操作對元組進行處理。 元組和列表在很多方面都是相似的,但它們有一個重要的不同點:元組不可修改,即不能對元組施加表 6.3 中的操作。如果序列的內容一經創建就不再改變,那么建議使用元組來 表示這個序列,好處是效率較高,而且可以防止出現誤修改操作。 元組的括號有時可以省略,例如用在賦值語句中。我們熟悉的為多個變量同時賦值其實 是元組賦值。下面是一些例子: ``` >>> 1,2,3 (1, 2, 3) >>> x = 1,2,3 >>> x (1, 2, 3) >>> x,y,z = 1,2,3 >>> x 1 >>> y,z (2, 3) ``` 元組也可以嵌套,即元組的成員本身可以是元組,例如: ``` >>> t = ("Lucy",("Math",90)) >>> t[1][1] 90 ``` Python 是以面向對象的方式實現元組類型的,元組對象支持的方法見表 6.5。 | 方法 | 含義 | | --- | --- | | &lt;元組&gt;.index(x) | 返回 x 在&lt;元組&gt;中首次出現處的索引 | | &lt;元組&gt;.count(x) | 返回&lt;元組&gt;中 x 的出現次數 | 表 6.5 元組對象的方法 元組類型的名字 tuple 可以用作構造器,將一個字符串或列表轉換成元組對象。例如: ``` >>> tuple('hello') ('h', 'e', 'l', 'l', 'o') >>> tuple([1,2,3]) (1, 2, 3) >>> tuple(['hello','world']) ('hello', 'world') ```
                  <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>

                              哎呀哎呀视频在线观看