Understanding Basic Data Types in Go
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:
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:
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.
Interestingly, string in Go is immutable. Once a string is created, we cannot change its value.
