在 Julia 中解包不同大小的元组

问题描述 投票:0回答:1

我这里有一个Python代码:

>>> a, *b , c = (1,2,3,4)
>>> a
1
>>> b
[2, 3]
>>> c
4
>>> 

Julia 是否有类似的设施?

Julia 中的相同命令给出错误:“ * 不是一元运算符”

julia tuples unpack
1个回答
0
投票

您可以使用

...
运算符来实现此目的。 (需要 Julia 版本 1.9 或更高版本。)

julia> a, b..., c = (1, 2, 3, 4)
(1, 2, 3, 4)

julia> a
1

julia> b
(2, 3)

julia> c
4
© www.soinside.com 2019 - 2024. All rights reserved.