package main import ( "time" "fmt" ) const ( Man = 1 Female = 2 ) func main(){ timer := time.Now().Unix() if(timer % Female == 0){ fmt.Println("%d is Female", timer) fmt.Printf("%d is Female", timer) }else{ fmt.Println("%d is Man", timer) fmt.Printf("%d is Man", timer) } }
%d is Man 1529049077 // println輸出結果 1529049077 is Man // printf輸出結果
Printf : 可打印出格式化的字符串, Println不行;
package main import "fmt" const ( StrN = "123" IntN = 123 ) func main(){ fmt.Println(StrN) fmt.Printf("%s\n",StrN) fmt.Printf(StrN) fmt.Println(IntN) fmt.Printf("%d\n",IntN) fmt.Printf(IntN) }
看到源碼內容,相信你大體明白兩函數的區別了吧~;
總結一句話: println會根據你輸入格式原樣輸出,printf須要格式化輸出並帶輸出格式;函數
做者:不動峯
博客園: http://www.cnblogs.com/mylly/ 版權全部,歡迎保留原文連接進行轉載:)