initial commit
This commit is contained in:
commit
493ce92e02
62 changed files with 1213 additions and 0 deletions
27
variables/variables.go
Normal file
27
variables/variables.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
import "fmt"
|
||||
|
||||
func main(){
|
||||
// var declares 1 or more variables.
|
||||
var a = "initial"
|
||||
fmt.Println(a)
|
||||
// You can declare multiple variables at once.
|
||||
var b,c int = 1,2
|
||||
fmt.Println(b,c)
|
||||
|
||||
// Go will infer the type of initialized variables.
|
||||
var d = true
|
||||
fmt.Println(d)
|
||||
|
||||
// Variables declared without a corresponding
|
||||
// initialization are zero-valued. For example,
|
||||
// the zero value for an int is 0.
|
||||
var e int
|
||||
fmt.Println(e)
|
||||
// The := syntax is shorthand for declaring and
|
||||
// initializing a variable, e.g.
|
||||
// for var f string = "apple" in this case.
|
||||
// This syntax is only available inside functions.
|
||||
f := "apple"
|
||||
fmt.Println(f)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue