Go Basic Types šŸŽÆ

beginner
12 min

Go Basic Types šŸŽÆ

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 šŸ“

Variables are containers that store data. In Go, every variable must be declared before it can be used.

go
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.

go
name := "Jane"

Booleans šŸ’”

Booleans are used to represent true or false values. In Go, the bool type represents boolean values.

go
isAdult := true isStudent := false

Integers šŸ“

Go supports several integer types, including int8, int16, int32, int64, and uint8, uint16, uint32, and uint64.

go
minInt := int8(-128) maxInt := int64(9223372036854775807) minUint := uint8(0) maxUint := uint64(18446744073709551615)

Floating-point numbers šŸ’”

Floating-point numbers are used to represent real numbers. In Go, the float32 and float64 types are used to represent floating-point numbers.

go
pi := 3.141592653589793 piFloat32 := float32(3.141592653589793) piFloat64 := float64(3.141592653589793)

Strings šŸ“

Strings in Go are represented by the string type. Strings are sequences of bytes that are enclosed in double quotes.

go
greeting := "Hello, World!"

Constants šŸ’”

Constants are named values that cannot be changed after they are declared. In Go, constants are defined using the const keyword.

go
const pi = 3.141592653589793 const MaxInt32 int32 = int32(math.MaxInt32) const MinInt32 int32 = int32(math.MinInt32)

Quiz

Quick Quiz
Question 1 of 1

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! šŸŽÆ