Values
Values in Go cover numbers, strings, booleans, and compound types. They are the building blocks you combine to model data.
Key Points
- Strings concatenate with
+; numbers use arithmetic operators. - Booleans support the usual logical operators.
- Literals default to untyped until used in context.
- Go is statically typed - type conversions must be explicit.
package main
import "fmt"
func main() {
fmt.Println("go" + "lang")
fmt.Println("1+1 =", 1+1)
fmt.Println("7.0/3.0 =", 7.0/3.0)
fmt.Println(true && false)
fmt.Println(true || false)
fmt.Println(!true)
}golang
1+1 = 2
7.0/3.0 = 2.3333333333333335
false
true
false
Value Types Reference
| Type | Examples | Operations | Notes |
|---|---|---|---|
string | "hello", "go" + "lang" | Concatenation with + | Immutable UTF-8 encoded |
int | 1, 42, -10 | +, -, *, /, % | Platform dependent size (32 or 64-bit) |
float64 | 3.14, 7.0/3.0 | +, -, *, / | IEEE-754 64-bit floating point |
bool | true, false | &&, ||, ! | Logical operations only |