Standard library / go/token

go/token.IsIdentifier()

Checks Go identifier spelling and rejects keywords. Predeclared identifiers are allowed. Expected stdout: 'true false false\n'.

Formal Syntax & Structure

go syntaxgo
func IsIdentifier(name string) bool

Parameters & Attributes

NameTypeDescription
namestringIdentifier spelling to classify.

Return Value

bool

Checks Go identifier spelling and rejects keywords.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/token")
func main() {  fmt.Println(token.IsIdentifier("π2"), token.IsIdentifier("2x"), token.IsIdentifier("func"))}
Go Reference