Learning Go: Part 2 — Basic Data Types

Basic Data Types

Examples

// Variable declaration
var TrueVariable bool = true
var FalseVariable bool = false
var StringVariable string = "I am a string"// Shorthand variable declaration
OtherStringVariable := "I am a string"
// Taken from "Data Types in Go" - GeeksForGeeks. (https://www.geeksforgeeks.org/data-types-in-go/)// Go program to illustrate
// the use of integers
package main
import "fmt"
func main() { // Using 8-bit unsigned int
var X uint8 = 225
fmt.Println(X+1, X)
}
// Taken from "Data Types in Go" - GeeksForGeeks. (https://www.geeksforgeeks.org/data-types-in-go/)// Go program to illustrate
// the use of integers
package main
import "fmt"
func main() { // Using 16-bit signed int
var Y int16 = 32767
fmt.Println(Y+2, Y-2)
}
var lastLetter byte = 'A'
package mainimport "fmt"func main() {
// var x rune = 0x2318
var x rune = '⌘'
fmt.Printf("%c\n", x)
}
var a float32 = 30.45
var b float64 = 60.45
// Taken from "Data Types in Go" - GeeksForGeeks. (https://www.geeksforgeeks.org/data-types-in-go/)// Go program to illustrate
// the use of complex numbers
package main
import "fmt"
func main() { var a complex128 = complex(6, 2)
var b complex64 = complex(9, 2)
fmt.Println(a)
fmt.Println(b)
// Display the type
fmt.Printf("The type of a is %T and "+
"the type of b is %T\n", a, b)
}

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store