Last active
December 12, 2015 08:48
-
-
Save jamesadney/4746474 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
http://play.golang.org/p/3YP3gdwpFG | |
*/ | |
import "fmt" | |
func main() { | |
s := "This is a string." | |
b := []byte("This is a slice of bytes") | |
fmt.Println("## Strings and Bytes ##\n") | |
// As characters | |
fmt.Printf("%s\n", b) | |
fmt.Printf("%q\n", b) | |
fmt.Println() | |
fmt.Println(b) // default | |
fmt.Printf("%#v\n", b) // in go syntax | |
fmt.Println() | |
fmt.Printf("%x\n", s) // hex string | |
fmt.Printf("% x\n", b) // hex string with spaces | |
m := map[string]int{"dollars": 1000, "friends": 4} | |
fmt.Println("\n## Maps and Structs ##\n") | |
fmt.Printf("%v\n", m) // default | |
fmt.Printf("%#v\n", m) // go syntax | |
fmt.Println() | |
type T struct { | |
a int | |
b float64 | |
c string | |
} | |
t := &T{4, 10.2, "hey"} | |
fmt.Printf("%v\n", t) // default | |
fmt.Printf("%+v\n", t) // default with field names | |
fmt.Printf("%#v\n", t) // go syntax | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment