Inside the main function, create one variable and display it:
Go code
var name string = "Maya"
fmt.Println(name)Line-by-line explanation
vartells Go to create a variable.nameis the label.stringsays the box stores text.= "Maya"places text in the box.- Println reads and displays the stored value.
Expected output
MayaGo displays the value, not the variable’s label.
A variable can receive a new value of the same type later:
Go code
name = "Noah"
fmt.Println(name)Line-by-line explanation
- The variable already exists, so
varis not repeated. - The equals sign assigns a new string.
- Println displays the replacement value.
Expected output
NoahThe old value Maya has been replaced.