# Everything you need to know about Go-Lang - #3
You probably have heard about Google's cool language called Golang. Golang is a statically typed, compiled programming language designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson. It is similar to C/C++, but with memory safety, garbage collection, structural typing, and CSP-style concurrency.
This is the continuation of [Everything you need to know about Go-Lang - #2](https://geektech.codes/everything-you-need-to-know-about-go-lang-2), so if you have not read that then check that out first.
In the last article we learned about **constants**, **operators**, **conditional statements**, **looping statements**, and **structs**. Today we will be going over some conceptual parts of features you already use.
## Data Type
You have all heard of **data types**. In simple terms, it is the type of data a variable can store in it. Like `int` only stores values of integer, `float` stores numbers with a decimal, and `string` stores values within quotes. In golang, there are only four basic data types, which are :
1. Integers.
2. Floating Point Numbers.
3. Strings
4. Boolean Values (True/False)
## Integer
Numbers without any decimal values are called integers. We can define a variable integer by using the `int` keyword.
```go
var a int //declaring an integer type variable
```
Integer has different sub-categories with sizes for numbers of different lengths. Like int32 can store numbers of maximum size 32 bits. Here's the list of all the subcategories of integer and the maximum size of numbers they can store :
| Data Types | Size |
|:------------- | --------------------- |
| `int8`/`byte` | 8-bit signed integer |
| `int16` | 16-bit signed integer |
| `int32` | 32-bit signed integer |
| `int64` | 64-bit signed integer |
| Data Types | Size |
|:-------------- | ----------------------- |
| `uint8`/`byte` | 8-bit unsigned integer |
| `uint16` | 16-bit unsigned integer |
| `uint32` | 32-bit unsigned integer |
| `uint64` | 64-bit unsigned integer |
**Note: Signed Integer can hold both negative as well as positive values, but unsigned once can only store positive values**. **Both `int` and `uint` can store values up to 32 bits or 64 bits, depending on if you are using 32 bits or 64 bits operating system respectively. `runes` are a synonym of int32, it also represents Unicode points**.
```go
package main
import "fmt"
func main() {
const a int32 = 42424682
const b int16 = 3223
const c byte = 2
fmt.Printf("a: %T, b: %T, c: %T", a, b, c) // %T in printf function returns the type of the variable
}
```
Output :
```shell
a: int32, b: int16, c: uint8
```
*Note: You cannot assign a value of int type variable to an int8, int16, or int32 type variable, as Golang doesn't implicitly typecase values of higher data type to that of a lower one.*
## Floating Point Number
Floating-point numbers are those numbers with decimals. We can define a floating-point number by using the `float32` or `float64` keyword. Like :
```go
var b float64
var c float32
```
Float has two sub-categories, those are :
| Data Type | Size |
| --------- | ------------------------------------- |
| `float32` | 32-bit IEEE 754 floating-point number |
| `float64` | 64-bit IEEE 754 floating-point number |
*Note : The **IEEE Standard for Floating-Point Arithmetic** (**IEEE 754**) is a [technical standard](https://en.wikipedia.org/wiki/Technical_standard "Technical standard") for [floating-point arithmetic](https://en.wikipedia.org/wiki/Floating-point_arithmetic "Floating-point arithmetic") established in 1985 by the [Institute of Electrical and Electronics Engineers](https://en.wikipedia.org/wiki/Institute_of_Electrical_and_Electronics_Engineers "Institute of Electrical and Electronics Engineers") (IEEE). The standard [addressed many problems](https://en.wikipedia.org/wiki/Floating-point_arithmetic#IEEE_754_design_rationale "Floating-point arithmetic") found in the diverse floating-point implementations that made them difficult to use reliably and [portably](https://en.wikipedia.org/wiki/Software_portability "Software portability"). Many hardware [floating-point units](https://en.wikipedia.org/wiki/Floating-point_unit "Floating-point unit") use the IEEE 754 standard.*
```go
package main
import "fmt"
func main() {
var b float64 = 3445.2335
var c float32 = 434.83
fmt.Printf(" b: %T, c: %T\n", b, c) // %T in printf function returns the type of the variable
}
```
Output :
```shell
b: float64, c: float32
```
### Complex Numbers
The complex numbers are divided into two parts are shown in the below table. `float32` and `float64` are also part of these complex numbers. The in-built function creates a complex number from its imaginary and real parts and the in-built imaginary and real function extract those parts.
| Data Type | Description |
| ------------ | ----------------------------------------------------- |
| `complex64` | Contains `float32` as a real and imaginary component. |
| `complex128` | Contain `float64` as a real and imaginary component. |
```go
package main
import "fmt"
func main() {
var b complex64 = complex(45, 3)
var c complex128 = complex(23, 5)
fmt.Printf(" Value of b:%v of %T, Value of c: %v of %T\n", b, b, c, c)
}
```
Output :
```shell
Value of b:(45+3i) of complex64, Value of c: (23+5i) of complex128
```
## Boolean Type
Now oftentimes, in programming, all we have to deal with is true or false. Based on different conditions we perform different tasks. We could just use integer values or strings to perform tasks that boolean performs, but using boolean makes it more flexible and sensible. To use a boolean type we use the `bool` keyword. Boolean types only store `true` and `false`. Eg :
```go
package main
import "fmt"
func main() {
var isTrue bool = true
var isFalse bool = false
if isTrue {
fmt.Println(isTrue)
} else {
fmt.Println(isFalse)
}
}
```
Output :
```shell
true
```
## Strings
The string data type represents a sequence of Unicode code points. Or in other words, we can say a string is a sequence of immutable bytes, which means once a string is created you cannot change that string. A string may contain arbitrary data, including bytes with zero value in the human-readable form. Like :
```go
package main
import "fmt"
func main() {
var variable string = "GeekTech is"
var newVar string = " the best place to learn golang"
fmt.Println(variable, newVar)
}
```
Output :
```shell
GeekTech is the best place to learn golang
```
The `len(string)` function returns the length of a string. Like :
```go
package main
import "fmt"
func main() {
newVar := "Helo"
fmt.Println(len("Kello"))
fmt.Println(len(newVar))
}
```
Output :
```shell
5
4
```
You can get a single character from a string by using the index numbers. Everything inside a quote is counts as a character be it a letter, space, newline character, number or special character. Index of a string always starts with 0 and ends with number one less than its length. Like a string `hello`, in its 0th index contains the character `h` and the last `o` is contained in the 4th index. Like :
```go
package main
import "fmt"
func main() {
newVar := "Helo"
fmt.Println(newVar[2])
}
```
Now, what do you think will be the output? `l` ? `e`? Let's see :
Output :
```shell
108
```
Confusing right? Because it returned a random number. Actually, it's not a random number. 108 is the Unicode representation of `l`, or runes in the case of Go. So when we are extracting characters from a string, we are actually extracting the Unicode representation of it. So how do you get back the string representation of it? We just need to typecast it explicitly back to string.
```go
package main
import (
"fmt"
)
func main() {
newVar := "Helo"
fmt.Println(string(newVar[2]))
}
```
Output :
```shell
l
```
Now, what if you have numbers in a string and want to convert them back to integer how shall you do it? For that we need, to use `strconv` package. We use `strconv.Atoi(string)`. For example :
```go
package main
import (
"fmt"
"strconv"
)
func main() {
newVar := "56"
variable := "34"
fmt.Println(strconv.Atoi(newVar))
fmt.Println(strconv.Atoi(variable))
}
```
Output :
```shell
56 <nil>
34 <nil>
```
Now, what does `<nil>` means over here? `strconv.Atoi()` returns the value in `int` and an error. In this case, there are no errors hence it prints nil.
Similarly, if you want to convert integer to string use `strconv.Itoa` function.
```go
package main
import (
"fmt"
"strconv"
)
func main() {
newVar := 65
variable := 45
fmt.Println(strconv.Itoa(newVar))
fmt.Println(strconv.Itoa(variable))
}
```
Output :
```shell
65
45
```
**Note: All data types of Golang discussed above are of primitive data types.**
## Your Turn
Venture Go Libraries for [Strings](https://pkg.go.dev/strings) , and try out different functions like `len()` or `range()`
## Conclusion
This was a short tutorial, however, sometimes it's important to get certain fundamentals right. In this tutorial, we learned about data types. In the next edition, we shall be covering functions, pointers, and user input.
### Thanks For Reading,
Follow [us]() for more great articles.
Until Next Time,
Arindol Sarkar.