Python 1
Python 1
Python 1
Tokens
•Token is the smallest unit of any programming language. It is also known as Lexical Unit.
Types of token are-
i.Keywords
ii.Identifiers (Names)
iii.Literals
iv.Operators
v.Punctuators
(i) Keywords
Keywords are those words which provides a special meaning to interpreter. These
are reserved for specific functioning. These can not be used as identifiers, variable
name or any other purpose. Available keywords are as input, print, and, none,
while, for, def, del, def etc.
(ii) Identifiers
•These are building blocks of a program and are used to give names to different parts/blocks of
a program like - variable, objects, classes, functions.
• An identifier may be a combination of letters and numbers.
• An identifier must begin with an alphabet or an underscore( _ ).
Subsequent letters may be numbers(0-9).
• Python is case sensitive. Uppercase characters are distinct from lowercase characters (P and p
are different for interpreter).
• Length of an Identifier is unlimited.
• Keywords can not be used as an identifier.
• Space and special symbols are not permitted in an identifier name except an underscore( _ )
sign.
• Some valid identifiers are –
• Myfile, Date9_7_17, Z2T0Z9, _DS, _CHK FILE13.
• Some invald identifiers are –
• DATA-REC, 29COLOR, break, My.File.
(iv) Operators
An Operator is a symbol that trigger some action when applied to identifier (s)/ operand (s)
Therefore, an operator requires operand (s) to compute upon.
example : c = a + b
(v) Punctuators
punctuators are used to construct the program and to make balance between instructions and
statements. •Python has following Punctuators -
‘, ”, #, \, (, ), [, ], {, }, @. ,, :, .. `, =
DATA TYPES
Variables can hold values of different types called data types. like- character, integer, real, string.
• Anything enclosed in “ “ is considered as string in Python.
•Any whole value is an integer value.
• Any value with fraction part is a real value.
•True or False value specifies Boolean value.
Operators :-
The symbols that shows a special behavior or action when applied to operands are called
operators. For ex- + , - , > , < etc.
• Python supports following operators-
Selective Iterative