Linux/Unix > Python Essential Reference, Second Edition > 2. Lexical Conventions and Syntax > Identifiers and Reserved Words | See All Titles

< BACK | Make Note | Bookmark | CONTINUE >

155117184014003188065099048180054212144238241179195140058238110137104027027050077005253035

### Identifiers and Reserved Words

An identifier is a name used to identify variables, functions, classes, modules, and other objects. Identifiers can include letters, numbers, and the underscore character (`_` ), but must always start with a non-numeric character. Letters are currently confined to the characters A–Z and a–z in the ISO-Latin character set. Because identifiers are case sensitive, `FOO` is different from `foo`. Special symbols such as `$`, `%`, and `@` are not allowed in identifiers. In addition, words such as `if`, `else`, and `for` are reserved and cannot be used as identifier names. The following list shows all the reserved words:

    and                 elif                global              or
    assert              else                if                  pass
    break               except              import              print
    class               exec                in                  raise
    continue            finally             is                  return
    def                 for                 lambda              try
    del                 from                not                 while

Identifiers starting or ending with underscores often have special meanings. For example, identifiers starting with a single underscore such as `_foo` are not imported by the `from module import *` statement. Identifiers with leading and trailing double underscores such as `_ _init_ _` are reserved for special methods, and identifiers with leading double underscores such as `_ _bar` are used to implement private class members as described in Chapter 7, “Classes and Object-Oriented Programming.” General-purpose use of similar identifiers should be avoided.

| Last updated on 3/28/2002 Python Essential Reference, Second Edition, © 2002 New Riders Publishing

< BACK | Make Note | Bookmark | CONTINUE >

© 2002, O'Reilly & Associates, Inc.