2. Basic constructs
Types
● Golang is Statically typed programming Language
● Variables always have a specific type and that type cannot change
● Data types in Go can be categorized into two types
1. Basic Types
2. Composite Types
3. GO Types
Basic Types
● Boolean : bool
● String : string
● Integer Numbers
Signed : int int8 int16 int32 int64
Unsigned : uint uint8 uint16 uint32 uint64 uintptr
● Floating Point Numbers : float32 float64
● Complex Numbers : complex64 complex128
● byte // alias for uint8
● rune // alias for int32
// represents a Unicode code point
6. Variable Initialization
var a int=3 var (
var b float32 a int
var s string b float32=2
s string=”my”
)
a:= 5
s1:= ”myStr”
7. Complex Types
● Complex Numbers are of two types
complex64 : Both real and imaginary part are float32
complex128 : Both real and imaginary part are float64
● Default complex type is complex128
8. Byte and Rune
● byte // alias for uint8
● byte used to represent the ASCII character
● rune // alias for int32
● rune used to represent all UNICODE characters
var r byte := 'a' // byte as type is must
var r := 'a' // is rune => default type
9. References
● “The Way to Go: A Thorough Introduction to the Go Programming Language”,Ivo Balbaert
● “The Go Programming Language”,Alan Donovan,Brian Kernighan,Addison-Wesley
● https://golangbyexample.com/all-data-types-in-golang-with-examples/