Token in Python
In a Python program, the smallest individual units are known as tokens. Python has 5 types of tokens. They are given below:
Keywords are the reserved words that have special meanings, and these meanings cannot be changed. Keywords serve as basic building blocks for program statements.
Example: for, del, elif, else etc
Identifiers refer to the names of variables, functions, class, module, or other objects. For naming an Identifier, there are basic rules that we must follow. These rules are given below:
- The identifier does not begin with a digit.
For Example, 2num is an invalid Identifier name
- The first character of an identifier must be a letter(upper or lowercase) or an underscore, and the rest of the Identifier name can be underscored (‘_’), letter(uppercase or lowercase), or digits(0-9)
For Example: a1, _A are valid Identifier names.
- Identifier names are case-sensitive.
For Example, loan_amount, LOAN_AMOUNT are two different Identifier names.
- Punctuation characters such as $, @, and % are not allowed within the Identifier.
For Example, salary%amount, aBabu Nanjajjar, %cash are invalid Identifier names.
Python Literals are defined as data that is given in a variable or constant. Python supports the following literals:
A string Literal is a sequence of characters enclosed in quotes. The characters may be letters, numbers, special characters, and blank space.
We can use a string in the following ways in a Python program.
Using Single Quotes (‘): For example, a string can be written as ‘WELCOME’.
Using Double Quotes (“): Strings in double-quotes are the same as those in single quotes. Therefore ‘WELCOME’ is the same as “WELCOME”.
Using Triple Quotes (‘’’ ‘’’): We can specify multi-line strings using triple quotes. We can use as many single quotes and double quotes in a string within triple quotes.
For example, a multi-line string can be written as,
‘’’Good morning to all. “Welcome to the world of ‘programming’.“ Happy reading.’’’