如何在Python中将元组转换为数组?
假设我有一个元组t = (1,2,3,4)
。将其更改为数组的简单方法是什么?
我可以做这样的事情,
array = []
for i in t:
array.append(i)
但我更喜欢像 x.toArray() 之类的东西。
Let's say I have a tuple t = (1,2,3,4)
. What's the simple way to change it into Array?
I can do something like this,
array = []
for i in t:
array.append(i)
But I prefer something like x.toArray() or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想将元组转换为列表(正如您所希望的那样),请使用以下命令:
此外,我建议不要使用
tuple
作为变量的名称。If you want to convert a tuple to a list (as you seem to want) use this:
In addition I would advise against using
tuple
as the name of a variable.