VARIABLES  IN GO

VARIABLES IN GO

·

2 min read

Throughout this article I will be using vscode as my code editor ..You can use any code editor of your choice the main objective to make you familiar with how to declare golang variables

Screenshot from 2020-08-07 02-28-45.png

first create your a go file called main.go and import package main as i have done here

Then in our main function we will be having a and b ad the constant to be declared

Screenshot from 2020-08-07 02-49-24.png

we are going to go by the first method then i will show you the other method later on var is used to declare it as variable a is the name of the variable we are declaring int is the data type. For those who aren't familiar with data type i will not be going into that in this article but basically

  • int is data type that represent numbers

  • string are data type that represent words, sentences even numbers they are declared around quotes as i did above

next up is to print the variables we have put above for that we will need to import a package called

fmt

we import the above the main function, we do that with a keyword called

import

like this

import "fmt"

Screenshot from 2020-08-07 02-54-53.png

now we will print it with this command

fmt.Println(a)

fmt.Println(b)

then all is ready in your terminal run

go run main.go

Screenshot from 2020-08-07 02-59-06.png

you should see what you printed out

NOW THE SECOND WAY you can directly go like

a:= 5

then

b:= "figures"

then in your terminal

go run main.go

you should have same result Screenshot from 2020-08-07 03-04-33.png Thank You..That is all for today