Keywords And Identifiers In Go

This article will introduce keywords and identifiers in Go.

Keywords

Keywords are the special words which help compilers to understand and parse user code.

Up to now (Go 1.10), Go has only 25 keywords:
break     default      func    interface  select
case      defer        go      map        struct
chan      else         goto    package    switch
const     fallthrough  if      range      type
continue  for          import  return     var
They can be categoried as four groups:

These keywords will be explained detailedly in other articles.

Identifiers

An identifier is a token which must be composed of Unicode letters, Unicode digits (Number category Nd in Unicode Standard 8.0) and _ (underscore) and start with either an Unicode letter or _. Here,

Note, keywords can not be used as identifiers.

Identifier _ is a special identifier, it is called blank identifier.

Later we will learn that all names of types, variables, constants, labels, package names and package import names must be identifiers.

An identifier starting with an Unicode upper case letter is called an exported identifier. The word exported can be interpreted as public in many other languages.

Currently (Go 1.10), eastern characters are viewed as non-exported letters. Non-exported identifers are also called unexported identifers in many documentations.

Here are some legal exported identifers:
Player_9
DoSomething
VERSION
Ĝo
Ⲡ
Here are some legal non-exported identifers:
_
_status
memStat
book
π
一个类型
변수
エラー
And here are some tokens which are illegal to be used as identifers:
123
3apples
a.b
*ptr
$name
a@b.c
type // this is a keyword
Welcome to improve Go 101 articles by submitting corrections for all kinds of mistakes, such as typos, grammar errors, wording inaccuracies description flaws and code bugs.