Welcome to the first lesson in our Golang series! Today, we'll be diving into the world of Go basic types. By the end of this tutorial, you'll have a solid understanding of the most fundamental Go data types, and you'll be well on your way to writing your first Go programs.
Let's get started! š
Variables are containers that store data. In Go, every variable must be declared before it can be used.
var firstName string = "John"
var age int = 25š” Pro Tip: Go automatically infers the type if you don't specify it during the variable declaration.
name := "Jane"Booleans are used to represent true or false values. In Go, the bool type represents boolean values.
isAdult := true
isStudent := falseGo supports several integer types, including int8, int16, int32, int64, and uint8, uint16, uint32, and uint64.
minInt := int8(-128)
maxInt := int64(9223372036854775807)
minUint := uint8(0)
maxUint := uint64(18446744073709551615)Floating-point numbers are used to represent real numbers. In Go, the float32 and float64 types are used to represent floating-point numbers.
pi := 3.141592653589793
piFloat32 := float32(3.141592653589793)
piFloat64 := float64(3.141592653589793)Strings in Go are represented by the string type. Strings are sequences of bytes that are enclosed in double quotes.
greeting := "Hello, World!"Constants are named values that cannot be changed after they are declared. In Go, constants are defined using the const keyword.
const pi = 3.141592653589793
const MaxInt32 int32 = int32(math.MaxInt32)
const MinInt32 int32 = int32(math.MinInt32)What is the maximum value for an `int64` in Go?
In the next lesson, we'll dive deeper into Go and explore operators, control structures, and functions. Stay tuned! šÆ