[Go] Convert a string to a byte slice

Created on November 30, 2026

A conversion such as []byte("hello") copies the string bytes into a slice. The example prints the slice's type with reflect.TypeOf.

package main

import (
    "fmt"
    "reflect"
)

func main() {
    bytes := []byte("hello")
    fmt.Println(reflect.TypeOf(bytes))
}
[]uint8

byte is an alias for uint8, which is why the output says []uint8.

Go