Link Search Menu Expand Document

Intro to Go

Some Examples

Examples taken from https://gobyexample.com/. Here are a few key examples linked below.

Here’s a table that outlines common data types in Go, along with their descriptions and examples:

Data TypeDescriptionExample
intA signed integer type.var x int = 42
float64A double-precision floating-point type.var y float64 = 3.14
stringA sequence of characters.var name string = "Alice"
boolA boolean type, can be true or false.var isActive bool = true
byteAn alias for uint8, represents a byte.var b byte = 'A'
runeAn alias for int32, represents a Unicode code point.var r rune = 'A'
arrayA fixed-size sequence of elements of the same type.var arr [3]int = [3]int{1, 2, 3}
sliceA dynamically-sized sequence of elements of the same type.var s []int = []int{1, 2, 3}
mapA collection of key-value pairs.var m map[string]int = map[string]int{"one": 1, "two": 2}
structA composite data type that groups together variables.type Person struct { Name string; Age int }

This table provides a clear overview of the fundamental data types in Go, along with examples to illustrate their usage. If you have any specific questions about these data types or need further details, feel free to ask!

Some Resources

Create Module Tutorial