Token The smallest individual unit in a program is called Token. It is also called lexical unit. Types of token in Python are as follows: • Keyword • Identifier • Literal • Operators • Punctuators
Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.
Tokens in Python
Keyword Keywords are reserved words in a programming language which has a special meaning. Some keywords in Python are: ✓if ✓elif ✓else ✓True ✓False ✓or ✓and ✓for ✓while ✓import ✓break ✓continue ✓pass ✓def ✓in ✓del ✓class ✓global ✓try ✓raise ✓yield ✓return ✓is ✓from ✓as ✓finally ✓except ✓lambda ✓nonlocal ✓with
Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.
Keywords in Python
Identifier Identifier are used as a name to identify variables, list, dictionaries, classes, objects, variables, functions, etc. Some rules of making identifier: • It can be of any length. • The first character should be a letter or underscore ( _ ). • Keywords cannot be used as an identifier. • Digits can be used except in the first character of an identifier. • No special characters should be used except underscore ( _ ). For example:
hello _Hello Python1
Literals Literals are data items that have a fixed value. Types of literal are: 1. Numeric Literal 2. String Literal 3. Boolean Literal 4. None Literal 5. Literal Collections
Operators Operators are tokens that triggers some computation when applied to a variable and other objects in an expression. Types of Operators: 1. Arithmetic Operators 2. Relational Operators 3. Bitwise Operators 4. Logical Operators 5. Assignment Operators 6. Membership Operators 7. Identity Operators
Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.
Punctuators Punctuator are symbols used in a programming language to organise sentence, expression, statement and structure. For example: ' " () {} [] @ , : = ' ~ ; \ #
Expression Expression is any combination of characters and symbols that represent a value. For example: a+7, a*5+b+3, etc.
Statement Statement are used to take some actions or define instructions or functions. For example: print ("Hello") This statement will call print() function.
Function Function is a group of codes that has its name and it can be executed again by specifying its name.You will get to know more about functions in further chapters.
Blocks Blocks are the group of statements that is a part of another statement or functions. For example: a=5 b=3 if a>b: a=a-1 print("Hi")
Indentation are used to specify blocks. You cannot use indentation unnecessarily, it will raise an error.
Comments Comments are just an additional information source, which is read by the programmers, but ignored in execution process. In python, # symbol is used to specify comments.