28

is it possible to print back quotes in Go using back quotes : something like this:

package main

import "fmt"

func main() {
    fmt.Println(```) // for example I can do it with double quotes "\""
}
rookie
  • 7,723
  • 15
  • 49
  • 59

3 Answers3

28
package main

import "fmt"

func main() {
    // back ` quote
    fmt.Println((`back ` + "`" + ` quote`))
}

Raw string literals are character sequences between back quotes ``. Within the quotes, any character is legal except back quote. The value of a raw string literal is the string composed of the uninterpreted characters between the quotes; in particular, backslashes have no special meaning and the string may span multiple lines. String literals

peterSO
  • 158,998
  • 31
  • 281
  • 276
1

You can also do it with single quotes:

package main
import "fmt"

func main() {
   fmt.Printf("%c\n", '`')
}

https://golang.org/pkg/fmt#Printf

Zombo
  • 1
  • 62
  • 391
  • 407
  • I found this the most idiomatic; adapting it to the answer the question, it would be `fmt.Printf(\`back %c quote\`, '\`')` (see https://go.dev/play/p/pzvfPcz4pm2). – Kurt Peek Jan 23 '23 at 19:08
0

TLDR

fmt.Println("\x60")

\x: Hex see fmt

6016 9610 1408 matches the character ` grave accent


Go Playground

Carson
  • 6,105
  • 2
  • 37
  • 45