Learn GO: Creating Variables in GO Lang

RMAG news

I just started learning Go and I want myself to be fully committed to it. So, I thought may be should start writing about it. It will help me to basically learn each part in some more details and will also help me to track the progress.

I won’t be talking about why you should or should not use this language. I just finds this very beautiful and as I always wanted to learn a low level language.

So, let’s get started with our first tutorial on how to create variables in GO.

Go is an statically typed language. Basically, we need to assign a the variable type in order to create one like we in other languages such as TypeScript and C++.

For creating a variable in GO the syntax looks like this:

_var_ variableName type = “value”

For example, if I have to create a variable of string then I’d do something like this:

_var_ myVariable string = “hola hola!!”

However, type is not always necessary as we can also specify the type in value, like this:

_var_ myVariable = “hola hola!!”

As strings are in quotes which is used to define strings in a language.

Another version of creating variable is the below one. Which is quite fancy and short, and will probably makes you look like an expert.

myVariable := “hola hola!”

This is short declaration of a variable which is pretty useful and great.

Next we can also make creating variables more cooler 😎. By assinging several variables at once. Like this:

var me, myGF, myWife := “programmer”, “programmer”, “scientist”

Now, there are various data types in GO such as string, float, int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, uintptr, and so on. You read more about GO Data Types here.

There are other things in GO variables as well. Which I will be talking about in the next post, for now that’s it.

If you have questions of suggestions for me to improve do let me know.!!