python - 如何在 Python 中将元组更改为数组?

标签 python arrays tuples

假设我有一个元组 t = (1,2,3,4)。把它改成Array的简单方法是什么?

我可以做这样的事情,

array = []
for i in t:
    array.append(i)

但我更喜欢 x.toArray() 之类的东西。

最佳答案

如果您想将元组转换为 list(如您所愿),请使用:

>>> t = (1, 2, 3, 4)   # t is the tuple (1, 2, 3, 4)
>>> l = list(t)        # l is the list [1, 2, 3, 4]

此外,我建议不要使用 tuple 作为变量的名称。

关于python - 如何在 Python 中将元组更改为数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3687702/

相关文章:

python - 如何使用 PySimpleGUI 将结果打印到命令行而不是弹出窗口?

arrays - Matlab:将int数组转换为字符串数组?

javascript - 删除 Javascript 中的空子数组

python - 包含元组的列表列表到列表列表

python - 将元组列表写入文本文件并读回列表

python - 在 python 中解压 z01、z02、zip 文件

python长度的unicode字符串混淆

python - 在不下载文件的情况下在网站上查找音频文件的比特率

c - 读取 XML 文件并使用 C 打印标签