GO learning notes (GO data type)

Keywords: Python Oracle

The second day of GO learning, today I mainly learned some data types of GO.

The common data types of go are as follows

1 int (int, int8, int16, int32, int64)

2 float (float32, float64)

3 string

4 byte

5 bool

6 array

7 slice

8 map

9 channel

10 interface

11 strcut

Common data types are defined and used as follows

// int data type
    var int_ int
    var int_8 int8
    var int_16 int16
    var int_32 int64
    var int_64 int64
    fmt.Println(int_)
    fmt.Println(int_8)
    fmt.Println(int_16)
    fmt.Println(int_32)
    fmt.Println(int_64)
    // string
    var str string
    fmt.Println(str)

    // byte 
    var b byte
    fmt.Println(b)
    // bool
    var boolean bool
    fmt.Println(boolean)

    // float
    var f32 float32
    var f64 float64
    fmt.Println(f32)
    fmt.Println(f64)

    // array

    var arry [10] int
    arry[0] = 0
    arry[1] = 1
    arry[2] = -1
    var arry_str[10] string
    arry_str[0] = "hello"
    arry_str[1] = "world"
    fmt.Println(arry)
    fmt.Println(arry_str)

    // slice dynamic array, with initialization capacity of 0, can append elements through append, without using make initialization, and cannot be assigned by index, such as s[0]=1
    var s [] int
    fmt.Println(len(s)) 
    s = append(s, 1)
    s = append(s, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    s[0]=0
    fmt.Println(s)
    s1 := make([]int, 5, 10)
    s1[0] = 1
    s1 = append(s1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
    fmt.Println(s1)

    // map is the dictionary of python
    dict := make(map[string]int)
    dict["oracle"] = 1521
    fmt.Println(dict)

Because today's study has not reached 9 channel 10 interface 11 strcut, only the previous ones are recorded.
It should be noted that by default, most data types are defined but not initialized, and go will assign them initial values

Default when uninitialized
int 0
int8 0
int32 0
int64 0
float32 0
float64 0
bool false
string " "

Posted by furnissg on Fri, 03 Apr 2020 18:11:25 -0700