Basic Data Types in Go #
Data type is an important concept in programming. It specifies the size and type of variable values.
Go is a statically typed language, meaning that once a variable type is defined, it can only store data of that type.
Three Basic Data Types in Go #
- bool: Represents a boolean value, which can be either
true
orfalse
. - Numeric: Represents integer types, floating point values, and complex types.
- string: Represents a sequence of characters (text).
Example #
This example demonstrates the use of different data types in Go:
package main
import ("fmt")
func main() {
var a bool = true // Boolean
var b int = 5 // Integer
var c float32 = 3.14 // Floating point number
var d string = "Hi!" // String
fmt.Println("Boolean: ", a)
fmt.Println("Integer: ", b)
fmt.Println("Float: ", c)
fmt.Println("String: ", d)
}
Output: #
Boolean: true
Integer: 5
Float: 3.14
String: Hi!
Understanding basic data types is essential for working efficiently with variables, performing calculations, and controlling program flow in Go.