in Go 「 Trying to make you to fall in love with Golang 」 1 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
- Try it! the = symbol means "bind" in the example on the right, constants π and Pi are both bound to the literal 3.1416 constants can be declared both at package level (out of any function body) and in function bodies (local constants) 2 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
type in the declaration like this: if multiple typed constants are declared on the same line, then their types must be the same as the constants A and B in the above example 「Trying to make you to fall in love with Golang」 - Constants and Variables 3 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
it doesn't contains the = symbol. In this cas the compiler will autocomplete the incomplete lines for us by copying the missing part from the first preceding complete declaration. Try It! _ is a special (blank) identifier - you can read it as "skip" 4 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
can only be used in other constant declarations declared as const iota = 0 Helpful when we want to autogenerate constant values. Try It! 5 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
at run time. when declared within function bodies are called local variables when declared out of any function body are called package-level variables There are two variable declaration forms the standard one var lang string = "Go" the short one lang := "Go" - can only be used to declare local variables 「Trying to make you to fall in love with Golang」 - Constants and Variables 6 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
is followed by the name, eventually the type, the assignment operator (=) and the initial value. In pratice the type isn't specified since the compiler can deduce it by the initial value. 「Trying to make you to fall in love with Golang」 - Constants and Variables 7 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
must be omitted the assignment sign must be := instead of = Try It! 8 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/
(@night) {twitter.com, github.com, linkedin.com} / lucasepe 「Trying to make you to fall in love with Golang」 - Constants and Variables 10 / 10 Constants and Variables Luca Sepe Software Craftsman, Solution Architect, Trainer https://twitter.com/lucasepe/ https://github.com/lucasepe/ https://lucasepe.it/