Key Concepts

Review core concepts you need to learn to master this subject

Go Fmt .Print() and .Println()

The Go fmt package supports two closely-related functions for formatting a string to be displayed on the terminal. .Print() accepts strings as arguments and concatenates them without any spacing. .Println(), on the other hand, adds a space between strings and appends a new line to the concatenated output string.

fmt.Print("I", "am", "cool") // Iamcool fmt.Println("I", "am", "cool") // I am cool
Learn Go: fmt Package
Lesson 1 of 1
  1. 1
    fmt is one of Go’s core packages. We’ve used it for print information to the terminal using the method fmt.Println(). fmt has a broader purpose, helping us format data, which is why it’s sometime…
  2. 2
    fmt.Println() allows us to print to the terminal and view the data that we’re working with. It has some defaulting styling built-in that makes viewing data easier for us. fmt.Println() prints its _…
  3. 3
    Using fmt.Println() and fmt.Print() we have the ability to concatenate strings, i.e. combine different strings into a single string: guess := “C” fmt.Println(“Is”, guess, “your final answer?”) //…
  4. 4
    In addition to %v, Go has a variety of useful verbs (check their documentation for a comprehensive list). Let’s go over a few in this exercise, starting …
  5. 5
    While we’ve been using fmt methods to print things out, remember, it’s the formatter package. We have other methods that don’t print strings, but format them instead like fmt.Sprint() and fmt.Sprin…
  6. 6
    If we need to interpolate a string, without printing it, then we can use fmt.Sprintf(). Just like fmt.Printf(), fmt.Sprintf() can also use verbs: correctAns := “A” answer := fmt.Sprintf(“And the…
  7. 7
    Another helpful method from the fmt package is .Scan() which allows us to get user input! Let’s see an example of this in action: fmt.Println(“How are you doing?”) var response string fmt.Scan(…
  8. 8
    Wonderful work getting through the fmt package’s methods! There are many more methods that we didn’t include, but you can read through Go’s fmt documentation for more…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo