Formatted I/O with functions analogous to C's printf
and scanf
.
import ( "fmt" ) name := "Sam" date := time.Now() // simple fmt.Sprintf("Hi, my name is %v", name) result := fmt.Sprintf("Hello, %v! Today is %v, it's %02v:%02v now.", name, date.Weekday(), date.Hour(), date.Minute())
fmt.Println
is used for debugging purposes
import "fmt" fmt.Println("debug message")
log.Println
is used for logging purposes
import "log" log.Println("debug message")
log.Fatal
- logs the message and calls os.Exit(1)
log.Panic
- logs the message and calls panic
log.Print
- logs the message%v
= value in a default format
%+v
adds field names when printing struct%s
= string
%d
= base 10 integer
%t
= boolean word true
or false