printf and println



println

package main
import "fmt"

func main() {
  name := "jim"
  fmt.Println("Hello world %s"\n, name)
}

go run a.go will give us Hello world %s jim

printf

package main
import "fmt"

func main() {
  name := "jim"
  fmt.Printf("Hello world %s\n", name)
}

This time, we get Hello world jim

using %s and %d



package main
import "fmt"

func main() {
  my_name := "JimS"
  my_age := 34 
  my_height := 74
  my_weight := 180 
  my_eyes := "brown"
  my_hair := "black"

  fmt.Printf("My name is %s.\n", my_name)
  fmt.Printf("I'm about %d inches tall.\n", my_height)
  fmt.Printf("I used to be %d pounds heavy.\n", my_weight)
  fmt.Printf("I have %s eyes and %s hair.\n", my_eyes, my_hair)
  fmt.Printf("adding these %d, %d, %d equals %d\n", 
    my_age, my_height,my_weight, my_age + my_height + my_weight)
}

convert float to int



package main
import "fmt"

func main() {
    this := 20
    that := 30.2342

    fmt.Println("There =", this - int(that))
}