HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to GoVariablesData TypesOperatorsStringsArray & SliceMap (Dictionary)Conditions (if / switch)Loops (for)Functions
REFERENCE
📖 Overview
🖥️ Output
fmt.Println()fmt.Printf()fmt.Sprintf()
📦 Variables
🔢 Numbers & Math
✍️ String
📋 Array & Slice
🗂️ Map
🔁 Condition & Loop
🧩 Function
Go›REFERENCE›Output
🖥️

Output

Printing to the screen and formatting.

CommandDescription
fmt.Println()Prints values, adds a newline at the end.
fmt.Printf()Formatted output (does not add a newline).
fmt.Sprintf()Returns the formatted text WITHOUT printing it.

fmt.Println()

Try it yourself →

Prints values, adds a newline at the end.

Syntax

fmt.Println(value...)

Description

It is in the fmt package (requires import "fmt"). Prints multiple values separated by spaces and moves to the next line.

Example

package main
import "fmt"
func main() {
    fmt.Println("Hello", "World")
}

Expected output

Hello World

When to use?

Showing results, debugging.

Common mistakes

  • ⚠️ It will not compile without import "fmt".

fmt.Printf()

Try it yourself →

Formatted output (does not add a newline).

Syntax

fmt.Printf("format", values...)

Description

Prints with placeholders: %d for number, %s for text, %v for any value, %T for type. Add \n for a newline.

Example

package main
import "fmt"
func main() {
    fmt.Printf("%s is %d years old\n", "Alex", 36)
}

Expected output

Alex is 36 years old

When to use?

Tables, formatted reports.

fmt.Sprintf()

Try it yourself →

Returns the formatted text WITHOUT printing it.

Syntax

fmt.Sprintf("format", ...)

Description

Formats like Printf but doesn't print to the screen; returns the result as a string (assigned to a variable).

Example

package main
import "fmt"
func main() {
    s := fmt.Sprintf("Score: %d", 95)
    fmt.Println(s)
}

Expected output

Score: 95

When to use?

Creating and storing/concatenating text.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code