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()或一對圓括號() ,步驟是,
Reinitialize the tuple using () or tuple()
使用()或tuple()重新初始化元組
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 初始化 元組