How to split a string and assign it to variables

前端 未结 9 1587
无人及你
无人及你 2020-12-07 10:27

In Python it is possible to split a string and assign it to variables:

ip, port = \'127.0.0.1:5432\'.split(\':\')

but in Go it does not see

9条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-07 11:23

    Golang does not support implicit unpacking of an slice (unlike python) and that is the reason this would not work. Like the examples given above, we would need to workaround it.

    One side note:

    The implicit unpacking happens for variadic functions in go:

    func varParamFunc(params ...int) {
    
    }
    
    varParamFunc(slice1...)
    

提交回复
热议问题