Python元组 www.acgred.cn

元组与列表非常相似

元组:不可改变

列表:可以任意修改


  1. 创建和访问一个元组

    tuple1 = (1,2,3,4,5,6,7,8)

    tuple1[1] www.acgred.cn

    →2


  temp = (1)

  type(temp)

  →int

  故要创建单个元素的元组

  temp = (1,)


  8 * (8)

  →64

  8 * (8,)

  →(8,8,8,8,8,8,8,8)


2.更新和删除一个元组

  1. temp = ('太阳','月亮','星星','大地')

  2. temp = temp[:2] + ('我',) + temp[2:]

  3. temp

  4. →('太阳','月亮','我','星星','大地')

   

  del temp












猜你喜欢

转载自blog.csdn.net/qq_42345394/article/details/80856311
今日推荐