wx

关注公众号

cmp


Golang 标准库 - cmp

包 cmp 提供了与比较有序值相关的类型和函数。

func main() {
	value := ""
	defaultVal := "default"
	fmt.Println(cmp.Or(value, defaultVal))
	fmt.Println(cmp.Compare('a', 'b'))
	fmt.Println(cmp.Compare("abc", "def"))
	fmt.Println(cmp.Compare(12, 12))
	fmt.Println(cmp.Compare(123, 12))

    // Less函数使用 
    fmt.Println("\n=== Less函数 ===")
    fmt.Println(cmp.Less(8, 12))       // true 
    fmt.Println(cmp.Less(15.0, 15.0))  // false 
    fmt.Println(cmp.Less("zoo", "apple")) // false 
}
如有疑问关注公众号给我留言
wx

关注公众号

©2017-2023 鲁ICP备17023316号-1 Powered by Hugo