Sobes.tech
Junior — Middle

Can you explain what the rune type in the Go programming language represents?

sobes.tech AI

Answer from AI

In the Go language, the rune type is an alias for the int32 type and is used to store a single Unicode code point. This allows working with Unicode characters rather than just ASCII bytes.

Main points:

  • rune is a 32-bit integer that encodes a Unicode character.
  • It is used for convenient handling of characters in strings, as strings in Go are sequences of bytes, and rune allows working with characters as a whole.

Example:

var ch rune = '世' // Chinese character
fmt.Println(ch)       // prints the numeric code of the character
fmt.Printf("%c", ch) // prints the character itself

Thus, rune helps to correctly process and manipulate Unicode characters in Go.