Avatar ·

What is the difference between := and = operators in Go? Explain with examples

Hi! I just started learning Go and I can't understand the difference between := and =. Both operators seem to assign something, but the compiler complains if I confuse them. Here's an example code that doesn't work for me: ```go package main import "fmt" func main() { var name string name = "Alice" fmt.Println(name) // And this doesn't compile for some reason: var age int age := 25 // error: no new variables on left side of := fmt.Println(age) } ``` I read the documentation, but it's written in a complicated way. Explain in simple terms: when to use := and when to use =? And why in one case I can write `x := 10`, and in another `var x int = 10`? Also, I'm confused that in some examples I see := used inside functions, but not at the package level. Is this a limitation?