Understanding Basic Data Types in Go
Introducing Numerical Data Types
In Go, we use numerical data types to represent numbers. Specifically, in this lesson, we're focusing on int and float64. The int data type represents whole integer numbers, and the float64 data type signifies decimal numbers — numbers with a decimal point.
The largest value an int can store depends on the system. It's (2147483647) on a 32-bit system and (9223372036854775807) on a 64-bit system.. Here's an example of using the int number:
Now, let's move on to the float64 data type. We use float64 when dealing with numbers that have decimal points, also known as floating-point numbers. It provides a precision of 15–17 digits. Consider the following example:
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.
