The difference between Print, Println and Printf in Go

Print and Println
are similar to each other, only differ in format

  1. There will be blank lines between each item printed by Println, but not by Print, for example:
fmt.Println("go","python","php","javascript") // go python php javascript
fmt.Print("go","python","php","javascript") // gopythonphpjavascript
  1. Println will automatically wrap, Print will not, for example:
fmt.Println("hello")
fmt.Println("world")
// hello
// world
fmt.Print("hello")
fmt.Print("world")
// helloworld

Println 和 Printf

func main() {
    a:=10
    b:=20
    c:=30
    fmt.Println("a=", a , ",b=" , b , ",c=" , c)
    fmt.Printf("a=%d,b=%d,c=%d" , a , b , c)
}

% d is a placeholder, representing the decimal representation of a number. The placeholders in Printf correspond one-to-one with the following numeric variables. More placeholder reference: click here

Guess you like

Origin www.cnblogs.com/wangcc7/p/12709607.html