Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Your First Program · Lesson 5 of 9

The fmt Package

A free lesson from Swipe Coding · Go, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
fmt is short for "format" — you'll import it in nearly every Go file you ever write. 🐹

fmt.Println is the most common way to print output in Go. It prints its arguments separated by single spaces and automatically adds a newline at the end, so the next thing you print starts on a fresh line without any extra work.

fmt.Println("Hello, World!")
fmt.Println("This line starts fresh.")
Each fmt.Println call ends with an automatic newline, so the second message appears on its own line.

fmt.Print is a closely related function, but it does not add that trailing newline — whatever you print next continues right where the previous call left off, on the same line. Because of this, developers reach for fmt.Println far more often, unless they specifically want output to keep building on one line.

Quick check

What is the key difference between fmt.Print and fmt.Println?

🤖
This is the printing tool you will reach for constantly once your output gets more specific. 🐹

fmt.Printf gives you far more control by using a format string full of format verbs — placeholders that get replaced with values you pass afterward. %s stands in for a string, %d for an integer, %f for a floating-point number, %v for a value in its default format, and %T for a value's type. Unlike Println, Printf never adds a newline for you, so you have to include \n yourself wherever you want one.

name := "Maya"
age := 21
fmt.Printf("%s is %d years old\n", name, age)
%s is replaced by name and %d is replaced by age, printing "Maya is 21 years old" followed by a newline from the explicit \n.
Fill in the blank

The format verb ____ prints a value's type, which is especially useful for debugging.

🤖
A handy default when you just want to see a value and don't care about picking the exact right verb. 🔍

%v is a general-purpose "default format" verb: it works with almost any value — strings, numbers, booleans, and more — and prints a reasonable default representation of it, which makes it a convenient choice while you are still learning the more specific verbs.

True or false

fmt.Printf automatically adds a newline character at the end of its output, exactly like fmt.Println does.

Keep your streak going in Swipe Coding

Swipe through every level of Go on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →