Declare variable and assign value golang tutorial 3
Declare variable and assign value golang tutorial 3
In last tutorial we have learnt how to declare variable.
write var keyword , followed by variable name and then variable type
var a int To assign a value to variable. It is very easy. just put equal sign and write your value. var a int = 420 or simply you can do like this if you have already declared variable. a = 420 another shortcut to declare varialbe and assign value is var a = 420 It will assume the type of variable. Lets unveil another very very shortcut way to declare a variable. a := 420 Just variable name , colon , equal sign and variable value. <strong>Source Code of normal way to declare variable.</strong> package main import "fmt" func main(){ var a int = 33 fmt.Print(a); }
Source Code of shortcut way to declare variable.
package main import "fmt" func main(){ var b = 343 fmt.Print(b);}
Source Code of shortest way to declare variable.
package main import "fmt" func main(){ c:=333 fmt.Print(c); }