Golang - Donovan Flashcards

Logs important stuff highlighted in the book.

1
Q

Variable Declaration

A

s := “” => only used in a function, cannot be used at the package level

var s string => initialized to zero value

var s = “” => rarely used, used when declaring multiple vars on same line

var s string = “” => explicity identifies the type of the var, important when its value is different then the zero val

:= is used for declaration

= is used for assignment

when using := at least one var on the left needs to be new or there will be compiler error

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

For Loop

A

Basic Form

for initialization; condition; post{

}

Like a While loop

for condition {

}

Like a inifinite loop

for {

}

With a range operator
ass := [1, 2, 3]

for index, val := range arr{

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Command Line Args

A

package = os

  • os.Args provides all the command line args
  • os.Args[0] is the command itself
  • os.Args[1:] => gives list of all the args (so escapes the first arg)

for index, val := range os.Args[1:]{

fmt.Println(index, val)

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Declarations in Go

A
  • there are four types of declarations
    1. var
    2. const
    3. type
    4. func
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Files in Go

A

package declaration

imports

package leve declarations

funciton level declarations

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Variable

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly