python 初始化 元组_在Python中重新初始化元组

python 初始化 元组

Python | 重新初始化元组 (Python | Reinitializing tuple)

In this tutorial, we will learn how can we reinitialize a tuple with a new set of elements/objects?

在本教程中,我们将学习如何使用一组新的元素/对象重新初始化元组?

To reinitialize a tuple, we can use tuple() or a pair of round brackets (), the steps are,

重新初始化元组 ,我们可以使用tuple()或一对圆括号() ,步骤是,

  1. Reinitialize the tuple using () or tuple()

    使用()或tuple()重新初始化元组

  2. Reassign the new set of objects/elements

    重新分配新的对象/元素集

Consider the below program,

考虑下面的程序,

# Reinitializing a tuple in Python

# tuple creation
x = ("Shivang", 21, "Indore", 9999867123)

# printing original tuple
print("x: ", x)
print("len(x): ", len(x))
print("type(x): ", type(x))
print()

# Reinitializing tuple using tuple()
x = tuple()
# assigning new  objects
x = (10, 20, 30, 40, 50)
print("x: ", x)
print("len(x): ", len(x))
print("type(x): ", type(x))
print()

# Reinitializing tuple using ()
x = ()
# assigning new  objects
x = ("Amit", 18, "Jaipur", 98.24, 8888888888)
print("x: ", x)
print("len(x): ", len(x))
print("type(x): ", type(x))
print()

Output

输出量

x:  ('Shivang', 21, 'Indore', 9999867123)
len(x):  4
type(x):  <class 'tuple'>

x:  (10, 20, 30, 40, 50)
len(x):  5
type(x):  <class 'tuple'>

x:  ('Amit', 18, 'Jaipur', 98.24, 8888888888)
len(x):  5
type(x):  <class 'tuple'>


翻译自: https://www.includehelp.com/python/reinitializing-a-tuple.aspx

python 初始化 元组

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值