0PricingLogin
Go Academy · Lesson

Printf Verbs

Format values precisely.

What Is a Verb?

fmt.Printf formats values using a format string. Inside it, a percent sign plus a letter is a verb that says how to print the next argument.

Example: %d for integers, %s for strings.

package main

import "fmt"

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

Remember the Newline

Unlike Println, Printf does not add a line break. Add \n yourself when you want one.

package main

import "fmt"

func main() {
    fmt.Printf("line one\n")
    fmt.Printf("line two\n")
}

All lessons in this course

  1. Printf Verbs
  2. Sprintf and Fprintf
  3. The Stringer Interface
  4. Scanning Input
← Back to Go Academy