import "reflect" func main() { mySlice := []int{1, 2, 3, 4, 5} sliceVal := reflect.ValueOf(mySlice) fmt.Println(sliceVal.Len()) // Output: 5 }
import "reflect" func main() { myString := "Hello, world!" stringVal := reflect.ValueOf(myString) fmt.Println(stringVal.Len()) // Output: 13 }This code uses `reflect.ValueOf` to create a `reflect.Value` instance of the `myString` variable, and then uses its `Len` method to determine the length of the string. Package/library: The package/library used in these examples is the built-in `reflect` package.