Go has three different quote marks, and each one means something different. Pick the wrong one and your program won’t compile — or it’ll behave in a surprising way. This page is a quick guide to choosing the right one.
The three quotes at a glance
| Quote | Looks like | What it makes | When to use it |
|---|---|---|---|
| Double quote | "hello" | A string | Most of the time — names, messages, any text |
| Single quote | 'A' | One character (a rune) | When you need exactly one letter, digit, or symbol |
| Backtick | `hello` | A raw string | Multi-line text, or text with lots of \ |
The rest of this page explains each one with examples.
Double quotes "..." — your everyday choice
Use double quotes for normal text. This is what you’ll write 90% of the time.
name := "Manikandan"
greeting := "Hello, world!"
fmt.Println(greeting)
Inside double quotes, you can use escape sequences. They start with a backslash \ and stand for special characters you can’t easily type:
| Write | And you get |
|---|---|
\n | a new line |
\t | a tab |
\" | a double quote " |
\\ | a backslash \ |
fmt.Println("Line 1\nLine 2")
// Line 1
// Line 2
fmt.Println("She said \"hi\"")
// She said "hi"
Single quotes '...' — exactly one character
Single quotes hold one character — no more, no less. And here’s the surprise: the value isn’t a string at all. It’s a number (a rune, which is just a Unicode code point).
letter := 'A'
fmt.Println(letter) // 65 (the Unicode number for A)
fmt.Printf("%c\n", letter) // A (printed as the character)
A few rules to keep in mind:
- Only one character between the quotes.
'A'works.'AB'is an error. - You can put any Unicode character, not just English letters:
'7','日','🐶'. - Escape sequences still work:
'\n'is the newline character.
You’ll mostly see single quotes in switch statements that compare characters:
switch c {
case 'y', 'Y':
fmt.Println("Yes")
case 'n', 'N':
fmt.Println("No")
}
Backticks `...` — raw strings
Backticks make a raw string. “Raw” means Go does not look for escape sequences. Whatever you write is exactly what you get — no surprises.
fmt.Println(`Hello\nWorld`)
// Hello\nWorld (the \n is just two characters, not a newline)
fmt.Println("Hello\nWorld")
// Hello
// World
Two big reasons to reach for backticks:
1. Multi-line text
Inside backticks, line breaks in your code show up in the output:
poem := `Roses are red,
Violets are blue,
Go has three quotes,
And now you do too.`
fmt.Println(poem)
2. Text with lots of backslashes
File paths on Windows and regular expressions are full of \. With double quotes you’d have to write \\ every time. With backticks, you don’t:
// Painful with double quotes:
path := "C:\\Users\\Mani\\Documents"
// Clean with backticks:
path := `C:\Users\Mani\Documents`
The one thing you can’t do: put a backtick character inside a backtick string. That’s the only limit.
Side-by-side: the letter A, three ways
package main
import "fmt"
func main() {
a := "A" // a string with one letter in it
b := 'A' // a rune (the number 65)
c := `A` // a raw string with one letter in it
fmt.Printf("%T %v\n", a, a) // string A
fmt.Printf("%T %v\n", b, b) // int32 65
fmt.Printf("%T %v\n", c, c) // string A
}
a and c are both strings — written differently, but the same type. b is something else entirely: a number.
Quick rules of thumb
- Just printing text? → double quotes
"..." - One character for a
switchor comparison? → single quotes'...' - Multi-line text, or text with lots of
\? → backticks`...`
Common mistakes
- Single quotes for a name:
name := 'Manikandan'won’t compile — single quotes only hold one character. - Expecting escapes inside backticks:
`Hello\nWorld`printsHello\nWorld, not two lines. - Mixing quote types:
"hello'is an error. Open and close with the same kind of quote.