pytago icon indicating copy to clipboard operation
pytago copied to clipboard

python unpack convert error

Open asukaminato0721 opened this issue 2 years ago • 2 comments

Describe the bug A clear and concise description of what the bug is.

tuple unpack

Python code example The simplest possible Python code example to demonstrate the bug.

def main():
  zz,*x = (0,0,0,0)
  print(zz,x)

if __name__ == '__main__':
  main()

Current behavior What the program currently outputs for the code example.

package main

import "fmt"

func main() {
	zz, x := 0, 0, 0, 0
	fmt.Println(zz, x)
}

Expected behavior A clear and concise description of what you expected to happen.

x becomes a tuple.

Go code example Optional. An example of a satisfactory Go code output for the Python example.

this may helps

https://stackoverflow.com/questions/19832189/unpack-slices-on-assignment

asukaminato0721 avatar Feb 23 '22 08:02 asukaminato0721

The only way to do this in Go would be:

package main

import "fmt"

func main() {
	zz := 0
	var x []int
	x = append(x, 0, 0, 0)
	fmt.Println(zz, x)
}

I don't know how easy this would be to implement, but it seems like it would be pretty difficult.

Elara6331 avatar May 07 '22 06:05 Elara6331

Actually, I just realized, there is a better way that's probably a bit easier:

package main

import "fmt"

func main() {
	zz, x := 0, []int{0, 0, 0}
	fmt.Println(zz, x)
}

Don't know how I didn't think of this before

Elara6331 avatar May 07 '22 06:05 Elara6331