Python Strings, Runes & UTF-8 Encoding Internals
Strings in Go are read-only slices of UTF-8 encoded bytes. Master the difference between byte length (len) and character count (utf8.RuneCountInString), rune literals, and string formatting.
"A string is a train of cargo containers (bytes). In ASCII, each passenger fits in 1 container. In Unicode UTF-8, an international passenger (rune) occupies 2 to 4 linked containers."
Deep Dive: How It Works
Strings as Byte Slices: string is an immutable slice of bytes with length.
Rune as Unicode Codepoint: rune is an alias for int32 representing a single Unicode character.
UTF-8 Iteration: for i, r := range s decodes UTF-8 runes automatically, advancing byte indices by rune width.
Syntax Blueprint
s := "Go 禅"
byteCount := len(s)
runeCount := utf8.RuneCountInString(s)
for i, r := range s { ... }Measure byte length with len(), Unicode count with utf8.RuneCountInString, and iterate runes with range.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Using s[0:3] on multi-byte international text expecting 3 characters.Why it happens: String slicing operates on raw bytes, which can split a multi-byte UTF-8 character in half.
How to fix: Convert to []rune first: runes := []rune(s); sub := string(runes[0:3]).
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Count Unique Vowels via Runes
Write a function countVowels(s string) int.
Iterate through the string runes, counting occurrences of 'a', 'e', 'i', 'o', 'u' (case-insensitive).
In main(), test with "Golang Runtime" and print "Vowels: %d".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.