Introducing Numerical Data Types
Discovering Boolean and Byte Data Types

Let's now shift focus to the bool and byte data types.

The bool data type in Go can hold one of two possible values: true or false. This data type receives extensive use in logical expressions and decision-making. Here's a simple example:

Go
var isEarthRound bool = true
fmt.Println(isEarthRound)  // This will print: true

var isEarthFlat bool = false
fmt.Println(isEarthFlat) // This will print: false

The byte data type is a special type of integer. Each symbol (character) is associated with some code. With byte data type we can store a symbol's code in a variable.Here's how to use it:

var firstLetterOfAlphabet byte = 'A'  // must be surrounded by SINGLE quotes
fmt.Println(firstLetterOfAlphabet) // This will print: 65 – the code for "A"

Note that in Go there is no special data type for storing characters. If you want to store a single symbol, store it inside the string data type. Let's explore it.

Exploring String Data Type

You'll find that the string data type is as common in Go as there are stars in the cosmos. Go treats string as a basic data type and uses it to store a sequence of characters — just a piece of text. The string is always surrounded by double quotes.

var welcome string = "Welcome to Go!"
fmt.Println(welcome) // This will print: Welcome to Go!

Interestingly, string in Go is immutable. Once a string is created, we cannot change its value.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal