use the fmt package to print a value in go

To print a value in Go, you can use the fmt package, which provides a set of functions for formatting and printing values. The most commonly used function is fmt.Println(), which prints a value to standard output followed by a newline character.

Here's an example:

main.go
package main

import "fmt"

func main() {
    name := "Alice"
    age := 30
    fmt.Println("Hello,", name)
    fmt.Println("You are", age, "years old.")
}
156 chars
11 lines

Output:

main.go
Hello, Alice
You are 30 years old.
35 chars
3 lines

In this example, we define two variables name and age, and print them using two separate fmt.Println() statements. The first statement uses string concatenation to include the value of name in the output, while the second statement uses multiple arguments to include the values of age and a string literal in the output. The fmt package automatically converts the values to strings and formats them according to the specified format.

gistlibby LogSnag