Created
February 17, 2023 17:20
-
-
Save knaveightt/92467b7450a23fcb667d539dd43980d9 to your computer and use it in GitHub Desktop.
Learn Go - Variables Summary
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables Examples | |
package main | |
import ( | |
"fmt" | |
"strconv" | |
) | |
// package level var that is publically visible (uppercase) | |
var ( | |
P int = 2 | |
) | |
// package level vars | |
var ( | |
actorName string = "Elisabeth" | |
companion string = "Smith" | |
doctorNumber int = 3 | |
season int = 11 | |
) | |
func main() { | |
// delcare g - block level visibility | |
var g int | |
g = 43 | |
// declare h | |
var h int = 44 | |
// declare i | |
var i2 float32 = 45.0 | |
i := int(i2) | |
ic := strconv.Itoa(i) | |
// print things | |
P = 66 // shadowing here | |
fmt.Println(g, h, i) | |
fmt.Printf("%v, %T\n", i, i) | |
fmt.Println(P) | |
fmt.Printf("%v, %T\n", ic, ic) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment