<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      元組

      tuple 元組

      元組中的元素不能修改。

      元組用 () 定義,元素之間用 , 分隔。

      程序示例:

      tuple1 = (1, 2.5, "hello")
      print(tuple1)  # (1, 2.5, 'hello')
      print(type(tuple1))  # <class 'tuple'>
      

      只有一個元素時,元素后面要加一個逗號。

      程序示例:

      tuple1 = ('apple')
      print(tuple1)  # apple
      print(type(tuple1))  # <class 'str'>
      tuple2 = ('apple',)
      print(tuple2)  # ('apple',)
      print(type(tuple2))  # <class 'tuple'>
      

      程序示例:

      # 空元組
      tuple1 = ()
      print(tuple1)  # ()
      print(type(tuple1))  # <class 'tuple'>
      tuple2 = tuple()
      print(tuple2)  # ()
      print(type(tuple2))  # <class 'tuple'>
      

      程序示例:

      # 類型轉換 tuple()
      list1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
      tuple1 = tuple(list1)
      print(tuple1)  # (1, 2, 3, 4, 5, 6, 7, 8, 9)
      print(type(tuple1))  # <class 'tuple'>
      tuple2 = tuple("hello")
      print(tuple2)  # ('h', 'e', 'l', 'l', 'o')
      print(type(tuple2))  # <class 'tuple'>
      tuple3 = tuple(range(1, 5))
      print(tuple3)  # (1, 2, 3, 4)
      print(type(tuple3))  # <class 'tuple'>
      

      程序示例:

      tuple1 = ('h', 'e', 'l', 'l', 'o')
      list1 = list(tuple1)
      print(list1)  # ['h', 'e', 'l', 'l', 'o']
      print(type(list1))  # <class 'list'>
      str1 = str(tuple1)
      print(str1)  # ('h', 'e', 'l', 'l', 'o')
      print(type(str1))  # <class 'str'>
      print(str1[2])  # h,元組整體轉為字符串,( 是索引為 0,' 是索引為 1,h 是索引為 2
      

      程序示例:

      # 索引
      tuple1 = ('h', 'e', 'l', 'l', 'o')
      print(tuple1[1])  # e
      print(tuple1[-1])  # o
      

      程序示例:

      # 切片
      tuple1 = (1, 2, 3, 4)
      print(tuple1[::-1])  # (4, 3, 2, 1)
      

      程序示例:

      tuple1 = (1, 2, 3, 4)
      print(len(tuple1))  # 4
      print(max(tuple1))  # 4
      print(min(tuple1))  # 1
      

      程序示例:

      tuple1 = (1, 2, 3, 4)
      print(tuple1)  # (1, 2, 3, 4)
      del tuple1
      # print(tuple1)  # NameError: name 'tuple1' is not defined. Did you mean: 'tuple'?
      

      程序示例:

      tuple1 = (1, 2, 3, 4)
      tuple2 = ("a", "b", "c", "d")
      tuple3 = tuple1 + tuple2
      print(tuple3)  # (1, 2, 3, 4, 'a', 'b', 'c', 'd')
      tuple4 = tuple1 * 3
      print(tuple4)  # (1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4)
      print("e" in tuple4)  # False
      print("e" not in tuple1)  # True
      

      程序示例:

      tuple1 = (1, 2, 3, 4)
      # tuple1[2] = 4  # TypeError: 'tuple' object does not support item assignment
      

      程序示例:

      tuple1 = (1, 2, 3, 4, 1, 2, 1)
      print(tuple1.count(1))  # 3
      print(tuple1.count(10))  # 0
      tuple2 = ("hello", "world", "good", "morning")
      print(tuple2.index("good"))  # 2
      # print(tuple2.index("well"))  # ValueError: tuple.index(x): x not in tuple
      

      程序示例:

      # 遍歷元組
      tuple1 = ("hello", "world", "good", "morning")
      for i in tuple1:
          print(i)
      

      結果:

      hello
      world
      good
      morning
      

      程序示例:

      # 遍歷元組
      tuple1 = ("hello", "world", "good", "morning")
      for index, value in enumerate(tuple1):
          print(index, value)
      

      結果:

      0 hello
      1 world
      2 good
      3 morning
      

      程序示例:

      # 遍歷元組
      tuple1 = ("hello", "world", "good", "morning")
      for i in range(len(tuple1)):
          print(i, tuple1[i])
      

      結果:

      0 hello
      1 world
      2 good
      3 morning
      

      元組定義時的 () 并不是必須的。

      程序示例:

      t1 = 1,
      print(t1)
      print(type(t1))
      

      結果:

      (1,)
      <class 'tuple'>
      
      posted @ 2025-11-02 00:21  YouKong  閱讀(4)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 国产区一区二区现看视频| 亚洲中文字幕无码中文字| 亚洲国产欧美一区二区好看电影| 国产一区二区不卡精品视频| 国产激情一区二区三区不卡| 国语自产少妇精品视频蜜桃 | 亚洲 欧美 中文 日韩aⅴ| 国产精品蜜臀av在线一区| 国产亚洲欧美日韩在线一区| 海丰县| 国内极度色诱视频网站| 蜜臀一区二区三区精品免费| 天堂va亚洲va欧美va国产| 枣强县| 美女一区二区三区亚洲麻豆| 黑森林福利视频导航| 欧美福利在线| 亚洲国产日韩欧美一区二区三区 | 成人污视频| 色综合色综合久久综合频道| 国产精品av免费观看| 中文字幕日韩有码一区| 亚洲精品视频一二三四区| 四虎国产精品永久在线| 亚洲精品一区国产精品| 日韩黄色av一区二区三区| 久久人妻国产精品| 亚洲精品国自产拍影院| 布尔津县| 性色av一区二区三区v视界影院| 国产精品亚洲综合网一区| 手机无码人妻一区二区三区免费| 午夜福利国产精品视频| caoporn免费视频公开| 青青国产揄拍视频| 国产成人精品a视频一区| 亚洲乱熟乱熟女一区二区| 国产办公室秘书无码精品99| 成人性做爰aaa片免费看| 国产亚洲精品aaaa片app| 亚洲激情视频一区二区三区|