FMT Package GoLang
FMT Package GoLang
F as in File
“... read from a specified io.Reader …”
io as in input output
exercise
create a program
that uses fmt.Scanln to receive keyboard input
does some calculation using that input
and then uses fmt.Println to display results
Review
● fmt package
○ Print
■ Print
■ Printf
■ Println
○ Scan
■ Scan
■ Scanf
■ Scanln
○ Sprint
■ Sprint
■ Sprintf
■ Sprintln
● variadic
○ func sum(numbers ...int) {
}
○ sum(aSlice...)
● verbs
○ %v
● receiving user input
var meters float64
fmt.Print("Enter meters swam: ")
fmt.Scanln(&meters)
● http://godoc.org/reflect
○ fmt.Println("a - ", reflect.TypeOf(a), " - ", a)
Review Questions
fmt package
● Describe the difference between Print, Printf, and Println
fmt package
● What are formatting verbs and how are they used?
● What is the default formatting verb?
fmt package
● What is the difference between Print, Fprint, & Sprint?
○ Read the documentation
■ describe how Sprint is used
● provide a screenshot of code you wrote to illustrate Sprint
■ speculate as to how Fprint might be used
○ What is an io.Writer
■ describe an io.Writer using quotes from the documentation
● take a screenshot of the io.Writer source code and include it
as a curio in your description
○ (a curio is something that you don’t understand yet but which is interesting)
...params
args...