pro*_*eek 18 python arrays tuples
假设我有一个元组t = (1,2,3,4).将其更改为Array的简单方法是什么?
我可以做这样的事情,
array = []
for i in t:
array.append(i)
Run Code Online (Sandbox Code Playgroud)
但我更喜欢像x.toArray()之类的东西.
Mar*_*ers 58
如果要将元组转换为列表(如您所愿),请使用以下命令:
>>> t = (1, 2, 3, 4) # t is the tuple (1, 2, 3, 4)
>>> l = list(t) # l is the list [1, 2, 3, 4]
Run Code Online (Sandbox Code Playgroud)
另外,我建议不要使用tuple变量的名称.