golang中不同print的区别

· golang
  package main
  
  import (
      "fmt"
  )
  
  func main() {
      name, age := "1", "2"
      fmt.Print(name, age,"\n")
      w, b := 1, 2
      fmt.Print(w, b)
  
      // It is conventional not to worry about any
      // error returned by Print.
  
  }

结果输出:

  12
  1 2

printf: 需要一个特殊的格式来进行输出

  package main
  
  import (
      "fmt"
  )
  
  func main() {
      const name, age = "Kim", 22
      fmt.Println("%s is %d years old.\n",name,age)
  
      // It is conventional not to worry about any
      // error returned by Println.
  
  }

结果输出: Kim is 22 years old.

println: 在两个元素间都会产生一个空格,同时还会在末尾添加换行符

  package main
  
  import (
      "fmt"
  )
  
  func main() {
      const name, age = "Kim", 22
      fmt.Println(name, "is", age, "years old.")
  
      // It is conventional not to worry about any
      // error returned by Println.
  
  }

结果是:Kim is 22 years old.