2022-12-03
This commit is contained in:
19
chapter-2/02_declarations.go
Normal file
19
chapter-2/02_declarations.go
Normal file
@@ -0,0 +1,19 @@
|
||||
// can only use := inside functions (this is nearly always used in functions)
|
||||
// := can re-assign vars, as long as one assignment is new
|
||||
|
||||
package main
|
||||
|
||||
func main() {
|
||||
// declaration list
|
||||
var (
|
||||
x int
|
||||
y = 20
|
||||
z int = 30
|
||||
d, e = 40, "hello"
|
||||
f, g string
|
||||
)
|
||||
|
||||
// assign values to existing variables
|
||||
a := 10
|
||||
a, b := 20, "hello"
|
||||
}
|
||||
Reference in New Issue
Block a user