Menu Close

Go – How to print backslash in strings in go

Here, We will see how to print backslash in strings in go. It is very easy to print something to the standard output in Go. You have to just import fmt package and call Print(), Println() or Printf() function.

To print backslash in string, You just need to prepend one more backslash before to be printed backslash.

Go interpreter treats single backslash as escape sequence character. When you put two backslash then Go interpreter treats it as a single backslash character.

Example with code:

package main

import (

func main() {

  fmt.Println("Hello \\ go")

  fmt.Println("Hello \\\\ go")

  fmt.Println("Hello \\\\\\ go")



Hello \ go
Hello \ go
Hello \\ go

To learn more about golang, Please refer given below link:

Posted in golang, Miscellaneous


  1. vivoslot

    Hello, I believe your site might be having internet browser compatibility
    issues. When I take a look at your website in Safari, it looks fine
    however, if opening in Internet Explorer, it’s got some overlapping
    issues. I just wanted to provide you with a quick
    heads up! Apart from that, great website!

Leave a Reply

Your email address will not be published. Required fields are marked *