如何在Go中打印出切片的非连续部分?

Wondering if there is a way to print out non contiguous portions of slice in Gol?

Example:

words := []string{"Mary","had","a","little","lamb"}

and I want to print out "Mary" and "lamb" from the slice?

Something along the lines of:

fmt.Printf("%s ", words[0],[5])

...which obviously this won't work... Is there a way ? :(

Thanks a lot!!

You can index into the slice, you just are doing it wrong.

fmt.Printf("%s %s
", words[0], words[5])

Your syntax for indexing didn't work because the second variable was just the index stuff without words. Additionally your format string was wrong, a single %s which means Printf is only expecting a single argument after that. Gotta have one formatter per arg.