python创建空元组_用Python创建空元组

python创建空元组

Python | 空元组 (Python | empty tuple)

In python, we can also create a tuple without having any element. An empty tuple is created using a pair of round brackets, ().

在python中,我们也可以创建一个没有任何元素的元组 。 使用一对圆括号()创建一个空元组

Syntax:

句法:

    tuple_name = ()

Example 1:

范例1:

# Python empty tuple creation`
tuple1 = () 

# printing tuple 
print("tuple1: ", tuple1)
# printing length
print("len(tuple1): ", len(tuple1))
# printing type
print("type(tuple1): ", type(tuple1))

Output

输出量

tuple1:  ()
len(tuple1):  0
type(tuple1):  

Example 2:

范例2:

We can also create an empty tuple by initializing the tuple with tuple() – generally this method is used to clear/reinitialize the tuple.

我们也可以通过使用tuple()初始化元创建一个空元 组 -通常,此方法用于清除/重新初始化元组。

# Python empty tuple creation`
tuple1 = tuple() 

# printing tuple 
print("tuple1: ", tuple1)
# printing length
print("len(tuple1): ", len(tuple1))
# printing type
print("type(tuple1): ", type(tuple1))
print()

# non-empty tuple
tuple2 = (10, 20, 30, 40, 50)
# printing original tuple
print("tuple2: ", tuple2)
print()

# reinitialize
tuple2 = tuple()
print("After reinitialize...")
# printing tuple 
print("tuple2: ", tuple2)
# printing length
print("len(tuple2): ", len(tuple2))
# printing type
print("type(tuple2): ", type(tuple2))

Output

输出量

tuple1:  ()
len(tuple1):  0
type(tuple1):  

tuple2:  (10, 20, 30, 40, 50)

After reinitialize...
tuple2:  ()
len(tuple2):  0
type(tuple2):  


翻译自: https://www.includehelp.com/python/empty-tuple-creation.aspx

python创建空元组

你可能感兴趣的:(python,列表,anaconda,深度学习,spring,boot)