Download and install file.In terminal
go version
The Go programming language is an open source project to make programmers more productive.
Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.
In go we have sign and unsign int, float
var age1 int8
var numb uint8
var num2 int16
var age2 uint16
var numb3 int32
var numb4 uint32
var num float32
var num float64
List with fix length
var ages [3]uint8 =[3] uint8 {2,2,2}
// length is fix
names :=[4]string{"root","mario"}
names[1]="foo"
fmt.Println(ages,len(ages))
slice can be change
// define list
var score=[]int {100,12}
// change value
score[1]=32
// add to list
score=append(score,23)
example
//slice range
name:=[]int{1,2,3,4,5,6}
rangeOne:=name[1:4]
rangeTwo:=name[2:]
rangeThre:=name[:2]
age := 12
numFloat:=222.22
fmt.Print("Hello \n")
fmt.Println("Hi",age,"end")
fmt.Printf("age %d",age)
fmt.Printf("age %f",numFloat)
Work on strings
import (
"fmt"
"strings"
)
greeting :="Hello world!"
// return boolean
contain:=strings.Contains(greeting,"Hello")
fmt.Println(contain)
replace:=strings.ReplaceAll(greeting,"Hello","hi")
toUpper:=strings.ToUpper(greeting)
// return index word in string
index:=strings.Index(greeting,"w")
split:=strings.Split(greeting," ")
fmt.Println(split)
Sort ,Search in string
names:=[]string{"foo","boo","goo"}
sort.Strings(names)
fmt.Println(names)
sort.SearchStrings(names,"foo")
Sort, Seacrch
num:=[]int{98,7,6,5,44,3,3,2,2,1,1,0}
sort.Ints(num)
fmt.Println(num)
index:=sort.SearchInts(num,98)
fmt.Println(index)