简体   繁体   English

编辑一个元组。 并访问元组的索引

[英]Editing A tuple. and accessing the index of tuple

I have a tuple, and as I know its immutable, is there any indirect way to edit/add elements or remove some?我有一个元组,而且我知道它是不可变的,有没有间接的方法来编辑/添加元素或删除一些元素?

TUPLE_1 = (1,2,5,3,'kevin','messi') 

I want to edit the strings and convert it to a number.我想编辑字符串并将其转换为数字。 And also I want to print the index of the newly added number.而且我还想打印新添加的数字的索引。

You can convert it to a list and change elements:您可以将其转换为列表并更改元素:

TUPLE_1 = (1,2,5,3,'kevin','messi') 
LST_1 = list(TUPLE_1)

Now you can change elements.现在您可以更改元素。 If you need a tuple back:如果您需要一个元组返回:

TUPLE_2 = typle(LST_1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM