cs60

# encoding:utf-8
number_tuple = (1,2,3,4,5,6,7,8,9,10) # 创建一个元组,元组 创建后 不可更改,这是跟列表list的区别
string_tuple = (\'bc-----\',\'cde\',\'aaa\',\'sasdfa\')
hunhe_tuple = (1,2,3,\'bc\')

aaa = number_tuple[4]
bbb = string_tuple[0]
ccc = hunhe_tuple[3]
print(str( aaa )+str(bbb)+str( ccc ))
print(\'第一个是:{0},第二个是:{1},第三个是:{2}\'.format(aaa,bbb,ccc))
print(len(number_tuple+string_tuple+hunhe_tuple)) #打印以上三种列表类型里共有几个元素
print("(hello)" *4)

#元组的截取
print(string_tuple[1])
print(string_tuple[-1])
print(hunhe_tuple[3:])

#创建只包含一个元素的元组
a_tuple = (2,) #需要以为都好来消除歧义

#创建 tuple中的list
mixed_tuple = (1,2,3,[\'a\',\'b\'])
print(\'mixed_tuple:\' + str(mixed_tuple))

#更改混合元组里面的list的值,元组本身没有更改
mixed_tuple[3][0] = \'a--\'
mixed_tuple[3][1] = \'b--\'
print(\'mixed_tuple:\' + str(mixed_tuple))

分类:

技术点:

相关文章:

  • 2021-12-12
  • 2021-12-04
  • 2022-02-07
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-10
  • 2022-01-19
  • 2021-05-28
  • 2021-11-20
  • 2021-04-04
  • 2021-09-02
  • 2022-12-23
相关资源
相似解决方案