python入门基础教程随笔2-python数据结构-元组

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

转载于:https://www.cnblogs.com/cs60/p/5598521.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值