Ever wondered, what unicode is? In other words, there are so many special characters (i.e. §, ¥, ª) that needs something called as unicode to be represented. To hold this kind of special characters 'rune' comes into picture.
Just remember, the data type for 'rune' is 'int32'.
Let us understand 'rune' with the below example.
package main import "fmt" import "reflect" func main() { x := '§' y := '¥' fmt.Printf("The value of first special character is : %c, Unicode is : %U, and Type is : %s \n", x, x, reflect.TypeOf(x)) fmt.Printf("The value of second special character is : %c, Unicode is : %U, and Type is : %s \n", y, y, reflect.TypeOf(y)) }
So, in the above code, we have initialised the variable 'x' with the special character '§'.
And initialised the variable 'y' with the special character '¥'.
Now, in the print statement,
We have printed its unicode using '%U' to check if it is a genuine unicode character or not.
And in the output, we got its Unicode,
Similarly, the next print statement,
Prints the Unicode.
Now, if you check the datatype for the variables 'x' and 'y'. It is 'int32'.
And the variables that holds the special characters are 'rune' in Go.