python解包的概念_什么是Python中的元组解包?

在定义元组拆包之前,我们需要了解什么是元组。

元组:在Python中,元组用于存储不可变的对象。元组是不可变的Python对象的序列。元组是序列,元组不能更改,并且元组使用括号。它将值的(RHS)右侧分配给(LHS)左侧。换句话说,这称为将值的元组拆包为变量。在对元组进行解包时,LHS上的变量数应等于给定元组中的值数。在打包时,我们将值放入新的元组中,而在打包时,我们将这些值提取到单个变量中。

例子1tuple = ("nhooo.com", 132, "Employees") # tuple packing

(companyname , Employerscount ,Information) = tuple # tuple unpacking

print(companyname)

print(Employerscount)

print(Information)

输出结果nhooo.com

132

Employees

例子2tuple = ("RRS College of Engg and Technology", 6000, "Engineering") # tuple packing

(college, student, graduates) = tuple # tuple unpacking

# print college name

print(college)

# print no of student

print(student)

# print type of college

print(graduates)

输出结果RRS College of Engg and Technology

6000

Engineering

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值