Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




GO - RUNE


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.


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))  
}


Output :



 The value of first special character is : §, Unicode is : U+00A7, and Type is : int32
 The value of second special character is : ¥, Unicode is : U+00A5, and Type is : int32

So, in the above code, we have initialised the variable 'x' with the special character '§'.


java_Collections

And initialised the variable 'y' with the special character '¥'.


java_Collections

Now, in the print statement,


fmt.Printf("The value of first special character is : %c, Unicode is : %U, and Type is : %s \n", x, x, reflect.TypeOf(x))

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,


The value of first special character is : §, Unicode is : U+00A7, and Type is : int32

Similarly, the next print statement,


fmt.Printf("The value of second special character is : %c, Unicode is : %U, and Type is : %s \n", y, y, reflect.TypeOf(y))

Prints the Unicode.


The value of second special character is : ¥, Unicode is : U+00A5, and Type is : int32

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.