From the course: Go for Developers: Practical Techniques for Effective Coding
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Variables - Go Tutorial
From the course: Go for Developers: Practical Techniques for Effective Coding
Variables
- In Go, there are several ways to declare and initialize a variable. In some cases, there is more than one way to declare the exact same variable and value. Each method of declaration or initialization has its own place in the Go language. Go is a statically typed language, meaning that the type of the variable is known at compile time. This means that the type of the variable must be specified when the variable is declared. New variables can be declared with the var keyword and given a name and type. In Go, when declaring a new variable or asking for an argument to a function, the name of the variable comes first, followed by the type of the variable, so var name type. Here we are defining several variables of different types. For example, variable i is of type int and variable f is of type float64. Once a variable has been declared, any value of that variable's type can be assigned to it using the equal operator. For example, we are assigning the variable i to the value 42 and the…