Skip to Content
Go Realm v1 is released 🎉
TopicsData Types

Go (Golang) Data Types

Go is a statically typed language, meaning variables must have a defined type at compile time.

TypeDescriptionSize (bits)Range/Example
int ⬇️Signed integer (platform-dependent)32 or 64-2³¹ to 2³¹-1 (32-bit)
int88-bit signed integer8-128 to 127
int1616-bit signed integer16-32768 to 32767
int3232-bit signed integer32-2³¹ to 2³¹-1
int6464-bit signed integer64-2⁶³ to 2⁶³-1
uint ⬇️Unsigned integer (platform-dependent)32 or 640 to 2³²-1 (32-bit)
uint8 (byte)⭐8-bit unsigned integer80 to 255
uint1616-bit unsigned integer160 to 65535
uint3232-bit unsigned integer320 to 2³²-1
uint6464-bit unsigned integer640 to 2⁶⁴-1
float32⬇️32-bit floating-point32±1.18e⁻³⁸ to ±3.4e³⁸
float64⬇️64-bit floating-point64±2.23e⁻³⁰⁸ to ±1.8e³⁰⁸
boolBoolean (true/false)8var flag bool = true
stringImmutable UTF-8 text-s := "Hello, Go!"
Rune⭐Alias for int32 (Unicode code point)32var r rune = 'A'

Golang Formatting Verbs

VerbDescriptionExample TypesExample InputExample Output
%vDefault formatanyPerson{"John",25}{John 25}
%+vStruct fields with namesstructsPerson{"John",25}{Name:John Age:25}
%#vGo syntax representationanyPerson{"John",25}main.Person{Name:"John"}
%T⭐Type of the valueany"hello"string
%%Literal percent sign-"%%"%
%tBooleanbooltruetrue
%dBase-10 integerintegers4242
%bBase-2 (binary)integers42101010
%oBase-8 (octal)integers4252
%xBase-16 (hex), lowercaseintegers422a
%XBase-16 (hex), uppercaseintegers422A
%fDecimal point, no exponentfloats3.141592653.141593
%eScientific notation (e)floats3.141592653.141593e+00
%EScientific notation (E)floats3.141592653.141593E+00
%g%e or %f, whichever is more compactfloats3.141592653.141592653589793
%G%E or %f, whichever is more compactfloats3.141592653.141592653589793
%sPlain stringstrings"hello"hello
%qQuoted stringstrings"hello""hello"
%pPointer addresspointers&x0xc000010050
%c⭐Unicode characterrunes65A
%UUnicode format (U+1234)runes65U+0041

General Verbs

type Person struct { name string age int } // %v: The "default" format. For structs, this shows field values without names. fmt.Printf("%v", person) // {John 25} // %+v: For structs, includes field names. fmt.Printf("%+v", person) // {Name:John Age:25} // %#v: Go-syntax representation of the value. fmt.Printf("%#v", person) // main.Person{Name:"John", Age:25} //%T: Prints the type of a value. fmt.Printf("%T", "hello") // string
// Integer Formatting n := 42 fmt.Printf("%d %b %o %x %X", n, n, n, n, n) // Output: 42 101010 52 2a 2A // Float Formatting pi := math.Pi fmt.Printf("%f %.2f %e %E %g %G", pi, pi, pi, pi, pi, pi) // Output: 3.141593 3.14 3.141593e+00 3.141593E+00 3.141592653589793 3.141592653589793 // String and Rune Formatting s := "hello" r := 'A' fmt.Printf("%s %q %c %U", s, s, r, r) // Output: hello "hello" A U+0041 // Special Cases fmt.Printf("%%") // Prints literal % fmt.Printf("%t", true) // Prints boolean