最常用的几个打印语句和占位符
package main
import (
"fmt"
"time"
)
type Person struct {
Name string
}
func main() {
str := "xiaohaizi"
fmt.Printf("%s\n", str)
fmt.Println("Hello world")
age := 2023
s1 := fmt.Sprintf("今年是 %d 年", age)
s2 := fmt.Sprintln("哈哈哈")
fmt.Println(s1)
fmt.Println(s2)
people := Person{Name: "xhz"}
fmt.Printf("%v\n", people)
fmt.Printf("%+v\n", people)
fmt.Printf("%#v\n", people)
fmt.Printf("%T\n", people)
fmt.Printf("%f\n", 5.3012345)
fmt.Printf("%.2f\n", 5.3012345)
fmt.Printf("%5.2f\n", 5.3012345)
fmt.Printf("%-5.2f\n", 5.3012345)
fmt.Printf("%5.f\n", 5.3012345)
fmt.Printf("%.2s\n", "xhz")
}