From the course: Learning Go

Unlock this course with a free trial

Join today to access over 24,200 courses taught by industry experts.

Declare and initialize variables

Declare and initialize variables - Go Tutorial

From the course: Learning Go

Declare and initialize variables

- [Instructor] Go is a statically typed language. You have to set the type of each variable during the compilation process and you can't change variable types at runtime but with go syntax you can set types either explicitly or implicitly. And there are a couple of variations in syntax you can use. I'm going to create a new folder within my workspace, and I'm going to call it practice. And from now on most of these lessons will be in the practice folder. And as I did before I'm going to start with a main dot go file. So I'll copy this main dot go file from hello and I'll paste it into practice. I'll make sure I'm working in the right version. And now I'll add code to the main function. I'm going to clear the console so we know for sure we're running the current code. Here's one way of declaring a variable in go, I'll start with the keyword var and I'll create a variable named a string to set its type explicitly…

Contents