Tutorial by Examples

Go is a statically typed language, meaning you generally have to declare the type of the variables you are using. // Basic variable declaration. Declares a variable of type specified on the right. // The variable is initialized to the zero value of the respective type. var x int var s string va...
In Go, you can declare multiple variables at the same time. // You can declare multiple variables of the same type in one line var a, b, c string var d, e string = "Hello", "world!" // You can also use short declaration to assign multiple variables x, y, z := 1, 2, 3 ...
Go will throw an error when there is a variable that is unused, in order to encourage you to write better code. However, there are some situations when you really don't need to use a value stored in a variable. In those cases, you use a "blank identifier" _ to assign and discard the assign...
There are some situations where you won't be sure what type a variable is when it is returned from a function. You can always check a variable's type by using var.(type) if you are unsure what type it is: x := someFunction() // Some value of an unknown type is stored in x now switch x := x.(type...

Page 1 of 1