Page 58 - Information_Practice_Fliipbook_Class11
P. 58
3.2 Tokens
The word lexical refers to the vocabulary of a language. A statement in Python is a sequence of its lexical components,
called tokens, such as numbers, parentheses, and commas. Python has the following tokens (to be discussed in this
section): keywords, identifiers, literals, delimiters, and operators (see Fig 3.1).
Keywords
Operators Identifiers
Python
Tokens
Delimeters Literals
Fig 3.1: Tokens in Python
3.2.1 Keywords
Keywords (also called reserved words) are words whose meaning and usage are predefined in a programming language.
Thus, a keyword cannot be used for any purpose other than the one defined by the language. Every programming
language has a set of keywords. Some of the most commonly used keywords are shown in Table 3.2. Note that the
keywords are case-sensitive. For example, while True is a keyword, true is not.
Table 3.2: Keywords in Python
True False class is
finally continue for while
None try except def
not and or if
elif assert else import
pass break raise global
in from with print
input return continue as
To display the keyword list of Python, we can use the keyword module in Python.
>>> import keyword
>>> keyword.kwlist
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class',
'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global',
'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise',
'return', 'try', 'while', 'with', 'yield']
3.2.2 Identifiers
An identifier is a name for a Python object. For example, the identifiers name, age, rollNo, and marks may
be used to refer to the name, age, roll number, and marks of a student. Like any other programming language, Python
follows certain rules for framing identifiers, which are as follows:
An identifier should begin with an uppercase or lowercase alphabet or an underscore (_).
The first letter of the identifier (including an underscore) may be followed by an arbitrary combination of alphabets
(a-z, A-Z), digits (0-9), and underscore (_).
44 Touchpad Informatics Practices-XI

