Python基础合集 练习2 (元组)

元组不能被修改

tuple1 = (‘python’, 2, ‘true’, -314, ‘false’)
tuple2 = (‘小美’,)
print(tuple2)

只有一个元素的元组加逗号

tuple3 = (‘小猪’)
print(tuple3)

不加逗号变成字符串

str_tuple = tuple(‘python’)
print(str_tuple)

将python拆分成为单独一个个的字符串

tuple4 = tuple(range(1, 5, 2))
print(tuple4)

步长为2的range数据 (1, 3)

#变量 = tuple(range(start, stop, step))
print(tuple1[2])

第三个元素

print(tuple1[-1])

倒数第一个元素

num_tuple = (2, 4, 6, 8, 10)
id(num_tuple)
print(id(num_tuple))

如果要赋值用 + 将其连接

num_tuple = num_tuple + (22, 44, 66, 88)
print(num_tuple)

在这里插入图片描述
谢谢观看,制作不易,不喜勿喷
如果喜欢,请点赞加关注哟

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值