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 初始化 元组

  • 0
    点赞
  • 0
    评论
  • 1
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值