Programming languages need to process and organize data. That data is stored as binary numbers (numbers consisting of 0’s and 1’s) in the memory of your computer. In this way, binary numbers are used to represent many different things. Data types are designations by a programming language about what information is being stored. Go comes with a number of basic types, data types built into the programming language. It’s also possible to create your own types that combine these basic types into something more complex, but let’s first cover the data that you can store by default in Go.
Go has three basic categories for numbers:
Integers, or
int
s, are whole/counting numbers. You would use anint
to count the number of books on a shelf, the number of products in a warehouse, the number of people on a website, etc…Floating-point numbers, or
float
s, can include fractional data. You would use afloat
to store distances, percentages, and other quantities that required division or precision.Complex numbers,
complex
, are pairs of floating-point numbers where the second part of the pair is marked with the “imaginary” uniti
. Complex numbers are particularly useful when reasoning in 2-dimensional space and have other utilizations that make them relevant for involved calculations, but we won’t be discussing them at length in this course.