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):  <class 'tuple'>

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):  <class 'tuple'>

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

After reinitialize...
tuple2:  ()
len(tuple2):  0
type(tuple2):  <class 'tuple'>


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

python创建空元组

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值