Text
Go has a single type to represent some text, string
.
When you are writing some text for a string
, it's called a string literal. There are two kinds of string literals in Go:
- Raw – defined by wrapping text in a pair of
`
- Interpreted – defined by surrounding the text in a pair of
"
With raw, what ends up in your variable is precisely the text that you see on the screen. With interpreted, Go scans what you've written and then applies transformations based on its own set of rules.
Here's what that looks like:
package main import "fmt" func main() { comment1 := `This is the BEST thing ever!` comment2 := `This is the BEST\nthing ever!` comment3 := "This is the BEST\nthing ever!" fmt.Print(comment1, "\n\n") fmt.Print(comment2, "\n\n") fmt.Print(comment3, "\n") }
Running the preceding code gives...