zoukankan      html  css  js  c++  java
  • python 元祖

    # 作用 :存多个值,对比列表来说,元祖不可变(可以当做字典的key,主要是用来读)
    age = (11, 22, 33)
    t = (1, 2, ['a', 'b'])
    # t[2] = 2 # 输出结果:TypeError: 'tuple' object does not support item assignment
    t[2][0] = 'keke'
    print(t) # 输出结果:(1, 2, ['keke', 'b'])
    # 按索引取值
    print(t[2]) # 输出结果:['keke', 'b']
    # 切片
    print(t[0:2]) # 输出结果:(1, 2)
    # 成员运算in 和not in,for
    for i in age:
      print(i)

  • 相关阅读:
    BD String
    1114
    1083
    1084
    1108
    1087
    1145
    1217
    1164
    反射
  • 原文地址:https://www.cnblogs.com/keqing1108/p/13262952.html
Copyright © 2011-2022 走看看