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

python创建空元组

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

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创建空元组

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

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

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