python 删除元组元素

Posted F

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 删除元组元素相关的知识,希望对你有一定的参考价值。

 

#create a tuple
tuplex = "w", "j" ,"c", "e"
print(tuplex)
#tuples are immutable, so you can not remove elements
#using merge of tuples with the + operator you can remove an item and it will create a new tuple
tuplex = tuplex[:2] + tuplex[3:]
print(tuplex)
#converting the tuple to list
listx = list(tuplex)
#use different ways to remove an item of the list
listx.remove("e")
#converting the tuple to list
tuplex = tuple(listx)
print(tuplex)

 

以上是关于python 删除元组元素的主要内容,如果未能解决你的问题,请参考以下文章

python(9):元组

初学Python——元组

Python ❀ 列表与元组

Python ❀ 列表与元组

Python ❀ 列表与元组

python 元组操作总结