Getting started with GoLang: Tutorial for beginners

Table of Content

1. Hello World

package main

import "fmt"

func main() {
fmt.Println("Hello, World!")
}

2. Variables

func main() {// Here you not need to mention the data type explicitly
var a = 123
fmt.Println(a)

var b int = 2
fmt.Println(b)

var c = true
fmt.Println(c)

var d string = "Simple data types"
fmt.Println(d)

}

3. Switch Statements

var i = 2
switch i {

case 1:
fmt.Println("Value is 1")

case 2:
fmt.Println("Value is 2")

case 3:
fmt.Println("Value is 3")
}

4. Arrays

var a[2] string

a[0] = "One"
a[1] = "Two"

fmt.Println(a[0] , a[1])
fmt.Println(a)

// Output
One Two
[One Two]

5. Functions

func main() {   var a = 10
var b = 20
var c int
c = add(a,b)
fmt.Println("Addition Function Result :", c)
}

func add(num1, num2 int) int{

var result int
result = num1 + num2
return result

}
// output
Addition Function Result : 30

Conclusion

Mobile I Web I Data Science I AI — We write rich & meaningful content on development, technology, digital transformation & life lessons.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store