3.3. IdentifiersIdentifiers are the set of valid strings that are allowed as names in a computer language. From this all-encompassing list, we segregate out those that are keywords, names that form a construct of the language. Such identifiers are reserved words that may not be used for any other purpose, or else a syntax error (SyntaxError exception) will occur. Python also has an additional set of identifiers known as built-ins, and although they are not reserved words, use of these special names is not recommended. (Also see Section 3.3.3.) 3.3.1. Valid Python IdentifiersThe rules for Python identifier strings are like most other high-level programming languages that come from the C world:
No identifiers can begin with a number, and no symbols other than the underscore are ever allowed. The easiest way to deal with underscores is to consider them as alphabetic characters. Case-sensitivity means that identifier foo is different from Foo, and both of those are different from FOO. 3.3.2. KeywordsPython's keywords are listed in Table 3.1. Generally, the keywords in any language should remain relatively stable, but should things ever change (as Python is a growing and evolving language), a list of keywords as well as an iskeyword() function are available in the keyword module.
3.3.3. Built-insIn addition to keywords, Python has a set of "built-in" names available at any level of Python code that are either set and/or used by the interpreter. Although not keywords, built-ins should be treated as "reserved for the system" and not used for any other purpose. However, some circumstances may call for overriding (aka redefining, replacing) them. Python does not support overloading of identifiers, so only one name "binding" may exist at any given time. We can also tell advanced readers that built-ins are members of the __builtins__ module, which is automatically imported by the interpreter before your program begins or before you are given the >>> prompt in the interactive interpreter. Treat them like global variables that are available at any level of Python code. 3.3.4. Special Underscore IdentifiersPython designates (even more) special variables with underscores both prefixed and suffixed. We will also discover later that some are quite useful to the programmer while others are unknown or useless. Here is a summary of the special underscore usage in Python:
Core Style: Avoid using underscores to begin variable names
|