Golang-101-Basic Usage


Posted by jerryeml on 2021-03-11

Variable

var {your_variable} type = {your_variable_value}

example:

var variable_01 string = "haha"

var (
    a int
    b float
)

Notice

  • variable must be defined first
  • go is a static language
  • variable should be unique
  • If you already defined the variable and you should use it!

Constant

Const will not be modify in runtime
const identifier [type] = value

const (
    a = iota //0
    b        //1
    c        //2
    d = "ha" //ha ,iota += 1
    e        //"ha"   iota += 1
    f = 100  //iota +=1
    g        //100  iota +=1
    h = iota //7 回傳iota數量
    i        //8

    Unknown = 0
    Female  = 1
    Male    = 2
)

Notice

  • int const will not store in address,therefore it can not get address through memory

#golang #rookie #basic-101







Related Posts

[ 紀錄 ] 實戰練習 - 留言版 (實作前端)

[ 紀錄 ] 實戰練習 - 留言版 (實作前端)

欄column (下)筆記Day -3

欄column (下)筆記Day -3

[筆記] React 隨手記 (React 應用篇hooks、setInterval、.map、取陣列或物件的方法)

[筆記] React 隨手記 (React 應用篇hooks、setInterval、.map、取陣列或物件的方法)


Comments