In Go, data types define the type of data a variable can hold. Go is a statically typed language, meaning the type of a variable is determined at compile time.
Type | Description | Example |
---|---|---|
bool | Boolean (true/false) | var isGoAwesome bool = true |
string | Sequence of characters | var language string = "Go" |
int | Integer numbers (size depends on system) | var age int = 25 |
float32 / float64 | Floating-point numbers | var pi float64 = 3.1416 |
complex64 / complex128 | Complex numbers | var c complex128 = 1 + 2i |
byte | Alias for uint8 (unsigned 8-bit integer) | var b byte = 255 |
rune | Alias for int32 (used for Unicode characters) | var r rune = 'G' |
Go provides different integer types based on size:
Type | Size (bits) | Value Range |
---|---|---|
int8 | 8-bit | -128 to 127 |
int16 | 16-bit | -32,768 to 32,767 |
int32 | 32-bit | -2,147,483,648 to 2,147,483,647 |
int64 | 64-bit | -9 quintillion to 9 quintillion |
uint8 | 8-bit | 0 to 255 |
uint16 | 16-bit | 0 to 65,535 |
uint32 | 32-bit | 0 to 4,294,967,295 |
uint64 | 64-bit | 0 to 18 quintillion |
đš int
and uint
are system-dependent (either 32-bit or 64-bit).
Type | Size (bits) | Precision |
---|---|---|
float32 | 32-bit | 6-7 decimal places |
float64 | 64-bit | 15-16 decimal places |
đš float64
is preferred in Go for accuracy.
Go supports complex numbers:
var c1 complex64 = 1 + 2i
var c2 complex128 = 3.5 + 4.5i
đš complex64
uses float32
, while complex128
uses float64
for real and imaginary parts.
Strings in Go are UTF-8 encoded and immutable.
var message string = "Hello, Go!"
fmt.Println(message)
đš Strings can be concatenated using +
.
Booleans hold true
or false
values.
var isGoEasy bool = true
fmt.Println(isGoEasy)
đš Default value is false
.
Type | Description |
---|---|
array | Fixed-length collection of elements of the same type |
slice | Dynamically sized array |
map | Key-value pair collection (like dictionaries in Python) |
struct | Custom data structure |
pointer | Stores memory address of a variable |
interface | Defines a set of method signatures |
package main
import "fmt"
func main() {
var name string = "Go"
var version float64 = 1.22
var isStable bool = true
var users int = 5000000
var letter rune = 'G'
fmt.Println("Language:", name)
fmt.Println("Version:", version)
fmt.Println("Is Stable:", isStable)
fmt.Println("Number of Users:", users)
fmt.Println("First Letter:", letter)
}
Go-āϤ⧠āĻĄāĻžāĻāĻž āĻāĻžāĻāĻĒ āύāĻŋāϰā§āϧāĻžāϰāĻŖ āĻāϰ⧠āϝ⧠āĻāĻāĻāĻŋ āĻā§āϰāĻŋāϝāĻŧā§āĻŦāϞ āĻā§ āϧāϰāύā§āϰ āĻĄāĻžāĻāĻž āϏāĻāϰāĻā§āώāĻŖ āĻāϰāϤ⧠āĻĒāĻžāϰāĻŦā§āĨ¤ Go āĻāĻāĻāĻŋ statistically typed āĻāĻžāώāĻž, āĻ āϰā§āĻĨāĻžā§ āĻāĻŽā§āĻĒāĻžāĻāϞ āĻāĻžāĻāĻŽā§ āĻĄāĻžāĻāĻž āĻāĻžāĻāĻĒ āύāĻŋāϰā§āϧāĻžāϰāĻŖ āĻšāϝāĻŧāĨ¤
āĻāĻžāĻāĻĒ | āĻŦāϰā§āĻŖāύāĻž | āĻāĻĻāĻžāĻšāϰāĻŖ |
---|---|---|
bool | āϏāϤā§āϝ/āĻŽāĻŋāĻĨā§āϝāĻž (Boolean) | var isGoAwesome bool = true |
string | āĻā§āĻā§āϏāĻ āĻĄāĻžāĻāĻž | var language string = "Go" |
int | āĻĒā§āϰā§āĻŖāϏāĻāĻā§āϝāĻž (Integer) | var age int = 25 |
float32 / float64 | āĻĻāĻļāĻŽāĻŋāĻ āϏāĻāĻā§āϝāĻž (Floating-point) | var pi float64 = 3.1416 |
complex64 / complex128 | āĻāĻŽāĻĒā§āϞā§āĻā§āϏ āϏāĻāĻā§āϝāĻž | var c complex128 = 1 + 2i |
byte | uint8 āĻāϰ āϏāĻŽāϤā§āϞā§āϝ | var b byte = 255 |
rune | int32 āĻāϰ āϏāĻŽāϤā§āϞā§āϝ (āĻāĻāύāĻŋāĻā§āĻĄ āĻā§āϝāĻžāϰā§āĻā§āĻāĻžāϰ) | var r rune = 'G' |
āĻāĻžāĻāĻĒ | āϏāĻžāĻāĻ (āĻŦāĻŋāĻ) | āĻŽāĻžāύā§āϰ āĻĒāϰāĻŋāϏā§āĻŽāĻž |
---|---|---|
int8 | 8-bit | -128 āĻĨā§āĻā§ 127 |
int16 | 16-bit | -32,768 āĻĨā§āĻā§ 32,767 |
int32 | 32-bit | -2,147,483,648 āĻĨā§āĻā§ 2,147,483,647 |
int64 | 64-bit | -9 āĻā§āϝāĻŧāĻžāĻĄā§āϰāĻŋāϞāĻŋāϝāĻŧāύ āĻĨā§āĻā§ 9 āĻā§āϝāĻŧāĻžāĻĄā§āϰāĻŋāϞāĻŋāϝāĻŧāύ |
uint8 | 8-bit | 0 āĻĨā§āĻā§ 255 |
uint16 | 16-bit | 0 āĻĨā§āĻā§ 65,535 |
uint32 | 32-bit | 0 āĻĨā§āĻā§ 4,294,967,295 |
uint64 | 64-bit | 0 āĻĨā§āĻā§ 18 āĻā§āϝāĻŧāĻžāĻĄā§āϰāĻŋāϞāĻŋāϝāĻŧāύ |
āĻāĻžāĻāĻĒ | āϏāĻžāĻāĻ (āĻŦāĻŋāĻ) | āύāĻŋāϰā§āĻā§āϞāϤāĻž |
---|---|---|
float32 | 32-bit | 6-7 āĻĻāĻļāĻŽāĻŋāĻ āϏā§āĻĨāĻžāύ |
float64 | 64-bit | 15-16 āĻĻāĻļāĻŽāĻŋāĻ āϏā§āĻĨāĻžāύ |
đš Go-āϤ⧠float64
āĻŦā§āĻļāĻŋ āύāĻŋāϰā§āĻā§āϞ āĻšāĻāϝāĻŧāĻžāϰ āĻāύā§āϝ āĻŦā§āĻļāĻŋ āĻŦā§āϝāĻŦāĻšā§āϤ āĻšāϝāĻŧāĨ¤
Go-āϤ⧠āϏā§āĻā§āϰāĻŋāĻ āĻāĻŽāĻŋāĻāĻā§āĻŦāϞ (āĻĒāϰāĻŋāĻŦāϰā§āϤāύ āĻāϰāĻž āϝāĻžāϝāĻŧ āύāĻž)āĨ¤
var message string = "Hello, Go!"
fmt.Println(message)
var isGoEasy bool = true
fmt.Println(isGoEasy)
đš āĻĄāĻŋāĻĢāϞā§āĻ āĻŽāĻžāύ false
āĻšāϝāĻŧāĨ¤
āĻāĻžāĻāĻĒ | āĻŦāϰā§āĻŖāύāĻž |
---|---|
array | āĻāĻāĻ āϧāϰāύā§āϰ āĻāĻĒāĻžāĻĻāĻžāύā§āϰ āύāĻŋāϰā§āĻĻāĻŋāώā§āĻ āĻāĻāĻžāϰā§āϰ āϏāĻāĻā§āϰāĻš |
slice | āĻĒāϰāĻŋāĻŦāϰā§āϤāύāĻļā§āϞ āĻāĻāĻžāϰā§āϰ āĻ ā§āϝāĻžāϰ⧠|
map | āĻā§-āĻā§āϝāĻžāϞ⧠āĻĒā§āϝāĻŧāĻžāϰ āĻĄāĻžāĻāĻž āϏā§āĻā§āϰāĻžāĻāĻāĻžāϰ |
struct | āĻāĻžāϏā§āĻāĻŽ āĻĄāĻžāĻāĻž āϏā§āĻā§āϰāĻžāĻāĻāĻžāϰ |
pointer | āĻŽā§āĻŽā§āϰāĻŋ āĻ āĻŋāĻāĻžāύāĻž āϏāĻāϰāĻā§āώāĻŖāĻāĻžāϰ⧠āĻāĻžāĻāĻĒ |
interface | āĻŽā§āĻĨāĻĄ āĻĄā§āĻĢāĻŋāύāĻŋāĻļāύā§āϰ āĻāύā§āϝ āĻŦā§āϝāĻŦāĻšā§āϤ āĻšāϝāĻŧ |