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




GO - CONSTANT


Say in your program you need some values that should never be changed. And this is where constant comes into picture.


Let us simplify with the below example.


Example :



package main  
import "fmt"
      
func main() {  
    
    const x int = 4  
       
    x = 15 
    fmt.Println("The new value of x is :", x)  
}   


Output :



  cannot assign to x

So, in the above code we have created a constant 'x' using the 'const' keyword.



  const x int = 4

java_Collections

Once the value is assigned to 'x', it cannot be changed as it is a constant.


And that is the reason we ended up with the below error message.



  cannot assign to x