// Created on savesnippets.com ยท https://savesnippets.com/ZzasgPcmfapjoj package main import "fmt" func describe(x any) string { switch v := x.(type) { case int: return fmt.Sprintf("int %d", v) case string: return fmt.Sprintf("string of length %d: %q", len(v), v) case bool: return fmt.Sprintf("bool: %t", v) case []int: return fmt.Sprintf("[]int with %d elements", len(v)) case nil: return "nil" default: return fmt.Sprintf("unknown type %T", v) } } func main() { for _, x := range []any{42, "hello", true, []int{1, 2, 3}, 3.14, nil} { fmt.Println(describe(x)) } }