1.读文件
const filename = "./learn/abc.txt"
if value, err := ioutil.ReadFile(filename); err != nil {
fmt.Println(err)
} else {
fmt.Printf("%s\n", value)
}
2.switch
func grade(score int) string {
g := ""
switch {
case score < 0 || score > 100:
panic(fmt.Sprintf("Tihis is err: %d", score))
case score < 60:
g = "F"
case score < 100:
g = "A"
}
return g
}
panic() 终端程序,并报错

博客介绍了Go语言相关内容,包含读文件操作、switch语句使用,还提到panic()函数可终止程序并报错,这些都是Go语言编程中的重要知识点。
7万+

被折叠的 条评论
为什么被折叠?



