标签:filename 表达 nil hello printf name cas pre his
fileName := "a.txt"
contents ,err := ioutil.ReadFile(fileName)
if err != nil{
fmt.Println("文件不存在")
}else{
fmt.Printf("%s\n",contents)
}
fileName := "a.txt"
if contents ,err := ioutil.ReadFile(fileName);err!=nil{
fmt.Println("文件不存在")
}else{
fmt.Printf("%s\n",contents)
}
go 语言的switch 默认会加break
var c = 2
switch c {
case 1 :
fmt.Print(c)
case 2:
fmt.Print("hello")
case 3:
fmt.Print("world")
default:
fmt.Println("this is the end")
switch 后面可以不跟表达式
var score = 80
switch {
case score >90 :
fmt.Print(score)
case score >80:
fmt.Print("hello")
case score >70:
fmt.Print("world")
default:
fmt.Println("this is the end")
标签:filename 表达 nil hello printf name cas pre his
原文地址:https://www.cnblogs.com/paulversion/p/11570411.html