Blog

Python: Identifiers and Keywords

Identifiers

An identifier is a word used to name things. A variable name is one example of an identifier. Python has strict rules for variable names or identifiers. These are as follows:

  • An identifier must contain at least one character.
  • The first character of an identifiers must be an alphabetic letter (upper or lower case) or the underscore.
  • The remaining characters (if any) may be alphabetic characters (upper or lower case), the underscore, or a digit.
  • No other characters (including spaces) are permitted in identifiers.
  • A reserved word cannot be used as an identifier.

Examples of valid Python identifiers include:

  • x
  • x1
  • result
  • name_1
  • PORT

Keywords

Python reserves a number of words for special use that could otherwise be used as identifiers. Called reserved words or keywords, these words are special and are used to define the structure of Python programs and statements. None of the reserved words in Table may be used as identifiers. If you try to use it as a variable name then the interpreter will issue an error.

Table below lists all the Python reserved words.

andasassertbreak
classcontinuedefelif
elseexpectFalsefinally
forfromglobalif
importinislambda
Nonenonlocalnotor
passraisereturntry
Truewhilewithyield

To learn more join our Python course  

Leave a Reply

Your email address will not be published. Required fields are marked *