If you're looking for a datatype in Go that stores multiple values, that would be the slice. Slices are ordered collections of data that can change in size at runtime.
myIntegers := []int{5, 7, 4, 3} myStrings := []string{"hi", "there"} myStrings = append(myStrings, "gophers") The difference that Ian is alluding to is that slices in Go can only hold elements that share the same type. We can seemingly get around this by making a slice that holds values of type interface{}. myThings := []interface{}{"str", 1234} The interface{} type known as the "empty interface". Every type satisfies the empty interface and therefore any instance of any type can be stored in our slice. In practice, though, you won't often write code like this. I would not recommend using slices of empty interfaces in most circumstances. If you're someone who comes from a background of only dynamically typed languages like Python, slices may seem a bit overly restrictive with their type rules. In practice, though, this isn't generally a problem. You just have to write code with static typing in mind. Without knowing what you want to accomplish, however, it's hard to give a recommendation. Of course, I don't know your background. You may have known all this already :) On Tue, Jul 11, 2017 at 9:49 PM Ian Lance Taylor <i...@golang.org> wrote: > On Tue, Jul 11, 2017 at 9:20 PM, <andy.arm...@gmail.com> wrote: > > > > A python list can be written as: > > > > ["something", 1234, 56.78, "Another string"] > > > > What is Go's data type that has a similar structure / capability? > > The literal answer to your question is > []interface{}{"something", 1234, 56.78, "Another string"} > > A better answer would be: what are you trying to do? Don't try to > write Python in Go. They are very different languages. > > Ian > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.