Junior — Middle
Can you explain what a rune is in the Go programming language?
sobes.tech AI
Answer from AI
In the Go language, a rune (rune) is a data type representing a Unicode code point. Essentially, it is an alias for the int32 type, used for convenience when working with Unicode characters.
Runes allow working with characters that may occupy more than one byte in UTF-8. For example, a string in Go is a sequence of bytes, and a rune is a single Unicode character.
Example of using a rune:
package main
import "fmt"
func main() {
var r rune = '世'
fmt.Printf("Rune: %c, code: %U\n", r, r)
}
Output:
Rune: 世, code: U+4E16
Thus, a rune is a convenient way to work with Unicode characters in Go.