Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Runes | Data Types
Introductie tot Golang

bookRunes

Runes, also referred to as Characters, represent a single Unicode character. They are declared using the rune keyword:

index.go

index.go

copy
1
var 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

index.go

copy
1234567
package 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

index.go

copy
1
var myChar rune = 'ab' // Error: more than one character in rune literal
question mark

Which keyword is used for declaring a character variable?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 4

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

What happens if I try to assign more than one character to a rune?

Can you show an example of how to print a rune as a character instead of an integer?

Why does printing a rune sometimes show a number instead of a letter?

Awesome!

Completion rate improved to 1.96

bookRunes

Veeg om het menu te tonen

Runes, also referred to as Characters, represent a single Unicode character. They are declared using the rune keyword:

index.go

index.go

copy
1
var 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

index.go

copy
1234567
package 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

index.go

copy
1
var myChar rune = 'ab' // Error: more than one character in rune literal
question mark

Which keyword is used for declaring a character variable?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 2. Hoofdstuk 4
some-alt