1.”“用法
使用”“判断string变量是否为空。
输入:
var s string
if s == "" {
fmt.Println("s is empty")
} else {
fmt.Println("s is not empty")
}
输出:
s is empty
2.nil用法
使用nil判断结构体的指针是否为空。
输入:
var Str struct {
name string
age int
}
func main() {
var s *Str
if s == nil {
fmt.Println(" s is nil ")
} else {
fmt.Println(" s is not nil ")
}
}
输出: s is nil
3.len(s)用法
用于求数组、切片和字典的长度。
输入:
func main () {
var s [] string
if len(s) == 0 {
fmt.Println("s is empty")
} else {
fmt.Println("s is not empty")
}
}
输出: s is empty
注:个人总结,如有错误欢迎指出,谢谢!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Java Servlet & JSP Cookbook
Bruce W. Perry / O'Reilly Media / 2003-12-1 / USD 49.99
With literally hundreds of examples and thousands of lines of code, the Java Servlet and JSP Cookbook yields tips and techniques that any Java web developer who uses JavaServer Pages or servlets will ......一起来看看 《Java Servlet & JSP Cookbook》 这本书的介绍吧!