Welcome To Golang By Example

Menu
  • Home
  • Blog
  • Contact Us
  • Support this website
Menu

Print string with double quotes in Go (Golang)

Posted on April 7, 2021April 7, 2021 by admin

Table of Contents

  • Overview
  • Program for double-quoted string

Overview

The backslash is the escaping character. To print any string that contains literal double quotes, we need to escape both these quotes when the string is enclosed within double quotes. However, a string enclosed in backquotes is a raw literal string and doesn’t honor any kind of escaping. So back quotes can also be used to print a string with literal double quotes

Program for double-quoted string

package main

import "fmt"

func main() {
	fmt.Println("\"test\"")
}

Output

"test"

Noticed that we escaped both single quotes and double quotes within that string 

Program for back quotes

package main
import "fmt"
func main() {
    fmt.Println(`"test"`)
}

Output

"test"
  • go
  • Follow @golangbyexample

    Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2025 Welcome To Golang By Example | Design: Newspaperly WordPress Theme