GO學習第一天(基本語法)

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() 終端程序,並報錯

發佈了38 篇原創文章 · 獲贊 38 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章