Golang raw string literals and interpreted string literals
There are two different ways to represent string literals.
Raw String
Example
package main
import "fmt"
func main() {
s := `Go\tJava\nPython`
fmt.Println(s)
}
What do you think will be the output of the above program?
Output
Go\tJava\nPython
Raw strings are enclosed in back-ticks `. Here, \t and \n has no special meaning, they are considered as backslash with t and backslash with n. If you need to include backslashes, double quotes or newlines in your string, use a raw string literal.
Interpreted String
Example
package main
import "fmt"
func main() {
s := "Go\tJava\nPython"
fmt.Println(s)
}
Raw strings are enclosed in quotes ". Hence \t would be interpreted as tab and \n as new line. The above program will print,
Output
Go Java
Python