Runes
Runes, also referred to as Characters, represent a single Unicode character. They are declared using the rune
keyword:
index.go
1var myChar rune = 'a'
It's important to note that rune values are always enclosed in single quotes ('
). Therefore, we wrote 'a'
.
Note
Unicode is a standard that assigns a unique numerical value to each character, allowing computers to represent and process text from various languages and scripts. While it's not necessary to have an in-depth knowledge of Unicode, you can find more information on the official website.
Now, if we attempt to print the value, we might obtain an integer as output:
index.go
1234567package main import "fmt" func main() { var myChar rune = 'a' fmt.Println(myChar) // Outputs '97' }
This is because the corresponding decimal value for the character a
in the Unicode system is 97
. You can find a list of Unicode characters and their decimal values here.
Please note that a rune can represent only a single character at a time; therefore, the following is incorrect:
index.go
1var myChar rune = 'ab' // Error: more than one character in rune literal
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 1.96
Runes
Swipe to show menu
Runes, also referred to as Characters, represent a single Unicode character. They are declared using the rune
keyword:
index.go
1var myChar rune = 'a'
It's important to note that rune values are always enclosed in single quotes ('
). Therefore, we wrote 'a'
.
Note
Unicode is a standard that assigns a unique numerical value to each character, allowing computers to represent and process text from various languages and scripts. While it's not necessary to have an in-depth knowledge of Unicode, you can find more information on the official website.
Now, if we attempt to print the value, we might obtain an integer as output:
index.go
1234567package main import "fmt" func main() { var myChar rune = 'a' fmt.Println(myChar) // Outputs '97' }
This is because the corresponding decimal value for the character a
in the Unicode system is 97
. You can find a list of Unicode characters and their decimal values here.
Please note that a rune can represent only a single character at a time; therefore, the following is incorrect:
index.go
1var myChar rune = 'ab' // Error: more than one character in rune literal
Thanks for your feedback!