Example
// Here package keyword is used to
// include the main package in the program
package main
// import keyword is used to
// import "fmt" in your package
import "fmt"
// func is used to
// create function
func main() {
// Here, var keyword is used
// to create variables
// Pname, Lname, and Cname
// are the valid identifiers
var Pname = "CodingNinjas"
var Lname = "Go Language"
var Cname = "Keywords"
fmt.Printf("Portal name: %s", Pname)
fmt.Printf("\nLanguage name: %s", Lname)
fmt.Printf("\nChapter name: %s", Cname)
}

You can also try this code with Online C Compiler
Run Code
Output:
Portal name: CodingNinjas
Language name: Go Language
Chapter name: Keywords

You can also try this code with Online C Compiler
Run Code
This example is a Go program to illustrate the use of keywords.
List of keywords
Go has only 25 keywords

Identifiers
An Identifier can be a name of variables, functions, arrays, classes, and more like user-defined functions in the program. Identifiers are the basic requirements of any type of language. However, each language has its own rules for creating these identifiers. Identifiers are used for identification.
You can say that an identifier is a name given by the developer inside the program. it can be a variable name or function name or any user-defined functions in the go program."
Example
package main
import "fmt"
func main()
{
var name = "CodingNinjas"
}

You can also try this code with Online C Compiler
Run Code
There is a total of three identifiers in the above example.
- main: Name of the package
- main: Name of the function
- name: Name of the variable
Rules for Defining Identifiers
There are particular rules for defining a valid Golang identifier. All rules should be followed; otherwise, we will get the compile-time error.
- The name of an identifier should begin with the letter or the underscore(_). The names may contain letters' a-z' or' A-Z' or digits 0-9 in addition to a character'_'.
- The name of an identifier should no longer start with a digit.
- The name of an identifier is case-sensitive.
- Keywords aren't allowed to use as an identifier name.
- There is no limit to the length of a name of an identifier. However, it is really useful to apply an optimum length of 4 – 15 letters most effective.
Valid Identifiers Name
Abc
ABC
abc
aBc
_abc
_Abc123
Abc123_
Abc_123

You can also try this code with Online C Compiler
Run Code
Invalid Identifiers Name
123abc
if
else
continue
default, etc.

You can also try this code with Online C Compiler
Run Code
FAQs
-
In the go language, which is allowed for naming an identifier?
Only alphabetic characters, digits, and underscore.
-
An identifier name must start with?
An identifier name must start with lower case (a to z) or upper case (A to Z) alphabets or with an underscore (_).
-
Can a keyword be used as a variable name or constant?
No, A keyword can't be used as a variable name or constant.
Key Takeaways
In this article, we have extensively discussed Identifiers & Keywords topics and all the types and rules of defining identifiers. We learned that the program's building blocks are keywords and identifiers. A compiler uses them to define the type/kind and name of a specific variable or class function.
We hope that this blog enhances your knowledge regarding Identifiers & Keywords, and if you would like to learn more, check out our articles on Library. if you wish to know more about keywords and identifiers in other languages as well, you can visit Identifiers and keywords in C.Do upvote our blog to help other ninjas grow. Happy Coding!