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

                ##### 元組的存儲空間很小,訪問速度也快,但是用索引(index)來訪問,大量索引降低程序可讀性。 >用索引去訪問元組的用法:(差的可讀性) ```python tuple_x = ('XiaoMing',16,10010,'test@mail.com') print(tuple_x[0]) print(tuple_x[1]) print(tuple_x[2]) print(tuple_x[3]) -------------------------------------------------- 輸出: XiaoMing 16 10010 test@mail.com ``` >定義類似與其他語言的枚舉類型,也就是定義一系列的數值類型(一般可讀性)。定義了4個變量,對應0,1,2,3。也就是索引值。 ```python NAME,AGE,PHONE,EMAIL = range(4) print(tuple_x[NAME]) print(tuple_x[AGE]) print(tuple_x[PHONE]) print(tuple_x[EMAIL]) ------------------------------------------- 輸出: XiaoMing 16 10010 test@mail.com ``` >***推薦做法:***使用標準庫中`collections.namedtuple`替代內置`tuple`(優雅可讀性) ```python from collections import namedtuple # 第一個參數創建子類的名字,第二個參數傳入你要給每個索引定義的名字 Student = namedtuple('Student',['name','age','phone','email']) s = Student('XiaoMing',16,10010,'test@mail.com') print(s.name) print(s.age) print(s.phone) print(s.email) --------------------------------------------- 輸出: XiaoMing 16 10010 test@mail.com ``` 注:```s = Student('XiaoMing',16,10010,'test@mail.com')```也可以使用關鍵字參數:```s = Student(name='XiaoMing',age='11',phone='10010',email='test@mail.com')```
                  <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>

                              哎呀哎呀视频在线观看