In this tutorial you will learn about the Go Constants and its application with practical example.
Go Constants
Constants refers to immutable values. Constants are basically literals whose values cannot be modified or changed during the execution of program. The Constants are created in the same way you create variables but instead of using the var keyword we use the const keyword and by convention constant names are always uppercase.
Syntax :-
1 |
const <constant_name> = value |
Here, <constant_name> can be replaced with constant name.
Example :-
1 2 3 4 5 6 7 8 |
package main import "fmt" func main() { const x string = "Hello World" fmt.Println(x) } |
Go Escape Sequence
Escape sequence is a special string comprise a backslash (\) followed by a letter or by a combination of digits used to control output on monitor. Escape sequences are typically used to represent actions such as newline,carriage returns,tab movements and non printing characters over the monitor. The following table lists the common ANSI escape sequences and their meaning.
Escape sequence | Meaning |
---|---|
\\ | \ character |
\’ | ‘ character |
\” | ” character |
\? | ? character |
\a | Alert or bell |
\b | Backspace |
\f | Form feed |
\n | Newline |
\r | Carriage return |
\t | Horizontal tab |
\v | Vertical tab |
\ooo | Octal number of one to three digits |
\xhh . . . | Hexadecimal number of one or more digits |