Go for Beginners — Part 4

Print Method

fmt.Println() allows us to print to the console and view data we are working with. This is useful if we want to display data to the user or if we want to alert them that a certain thing has happened

fmt.Println("Println", "formats", "really well")
fmt.Println("Right?")
Println formats really well
Right?
fmt.Print("The answer is", ": ")
fmt.Print("12")
The answer is: 12
fmt.Print("Print","is","different")
fmt.Print("See?")
PrintisdifferentSee?

Printf Method

The Printf() Method allows us to concatenate strings which is really useful and can make your code look neater

selection1 := "soup"
selection2 := "salad"
fmt.Printf("Do I want %v or %v?", selection1, selection2)

Sprint + Sprintln Methods

At this stage you just need to understand that returning a value and printing a value are two different things and this Method returns values given to it

variableOne := "bruhMomento"
bruhMoment := fmt.Sprintln("Oh god hes even including variables in this such as",variableOne,"look at him go")
template := "I wish I had a %v."
pet := "puppy"
wish := fmt.Sprintf(template,pet)

Getting User Input with Scan()

Another useful Method in the fmt Package is Scan() which allows us to collect User Input

fmt.Println("How are you doing?")var response stringfmt.Scan(&response)fmt.Printf("My response was %v", response)

Summary

In Summary, the built-in fmt Package is incredibly useful and gives us a few tools to work with out of the box.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kodey Thomas

Kodey Thomas

Backend Developer, Probably listening to music and drinking coffee