Python Tokens
Python Tokens are the smallest unit of a Python program.The Python program is constructing expressions and statements using Tokens.
Python program is a group of different types of tokens, comments, and white spaces.
There are various tokens used in Python:
- Keywords
- Identifiers
- Literals
- Operators
1. Keywords
Python keywords are those predefine words which has a special meaning to an Interpreter to perform a task.In Python there are around 35 keywords.
In Python you can get the list of keywords using below code:
help("keywords")
You can get more details about any keywords using below code:
help("break")
2. Identifiers
Identifiers are used to identify the things.Identifiers are used with class, function, variable etc.
There are following rules to define an Identifier:
Valid Identifiers
Invalid Identifiers
3. Literals
Any constant value which is assigned to a variable that is called literal.There are following types of literals:
i. Numeric Literals
Numeric Literals are immutable (unmodifiable).There are three types of Numeric Literals:
- Integer
- Float
- Complex
ii. String Literals
A string literal is a sequence of characters.String always represent by single, double or triple quotes.
For Example:
iii. Boolean Literals
Boolean Literals can have only one value either True or False.In Python True represent the value as 1 and False represent the value as 0.
You can use True and False in a Numeric expressions.
For Example:
iv. Special Literals
None is a Special Literals in Python.You can use None with that field which is not created.
It is also used for end of lists in Python.
For Example:
v. Collection Literals
There are four different literal collections List literals, Tuple literals, Dict literals, and Set literals.For Example:
4. Operators
Operators are special symbols in Python that carry out arithmetic or logical computation.The value that the operator operates on is called the operand.
There are following types of Operators in Python:
- Arithmetic operators
- Comparison operators
- Logical operators
- Bitwise operators
- Assignment operators
- Special or identity operators
- Membership operators
No comments:
Post a Comment