

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Constants
incomplete
2: Computed Constants
incomplete
3: Comparing Go's Speed
incomplete
4: Formatting Strings in Go
incomplete
5: Runes and String Encoding
incomplete
6: Fix Bugs
incomplete
7: Fix Types
incomplete
8: Type Inference
incomplete
9: Format Practice
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
In many programming languages (cough, C, cough), a "character" is a single byte. Using ASCII encoding, the standard for the C programming language, we can represent 128 characters with 7 bits. This is enough for the English alphabet, numbers, and some special characters.
In Go, strings are just sequences of bytes: they can hold arbitrary data. However, Go also has a special type, rune, which is an alias for int32. This means that a rune is a 32-bit integer, which is large enough to hold any Unicode code point.
When you're working with strings, you need to be aware of the encoding (bytes -> representation). Go uses UTF-8 encoding, which is a variable-length encoding.
Interactive example available with JavaScript enabled.
There are 2 main takeaways:
rune type. It breaks strings up into their individual characters, which can be more than one byte long.Boots is a bear. (Not a dog, haters).
🐻
If you've got it right, you should notice that the emoji is only one rune, but it takes up 4 bytes.