栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 初始化 元组

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

x:  (10, 20, 30, 40, 50)
len(x):  5
type(x):  

x:  ('Amit', 18, 'Jaipur', 98.24, 8888888888)
len(x):  5
type(x):  


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

python 初始化 元组

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/834025.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号