use the fmt package to print a value of type string in go

To print a value of type string in Go, we can make use of the fmt package which provides a variety of formatting options for printing values to the standard output stream.

Here is an example code snippet that demonstrates how to use the fmt package to print a string value:

main.go
package main

import "fmt"

func main() {
   str := "Hello, World!"
   fmt.Printf("%s\n", str)
}
97 chars
9 lines

In this example, we create a variable str which holds the string value "Hello, World!". We then use the fmt.Printf function to print the value of str to the standard output stream. The format string %s specifies that the argument passed is a string value.

When we run this program, we should see the following output:

main.go
Hello, World!
14 chars
2 lines

gistlibby LogSnag