RT 1
RT 1
RT 1
Chapter- 2
Python Introduction
• In order to provide an input, process it and to
receive output, we need to write a program.
• Program, is a group of instructions which
controls processing.
• In other words, base for processing is ‘the
Program’.
• In this chapter we will come to know about
various element of processing like – character
set, token, expressions, statements, input.
Python Character Set
• Character Set-is a group of letters or signs which
are specific to a language.
• Character set includes letter, sign, number,
symbol.
– Letters: A-Z, a-z
– Digits: 0-9
– Special Symbols: _, +, -, *, /, (, ), {, } . . . Etc.
– White Spaces: blank space, tab, carriage return,
newline, formfeed etc.
– Other characters: Python can process all characters of
ASCII and UNICODE.
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
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 in Python are-
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.
Literals / Values
• Literals are often called Constant Values.
– Literal collections
String Literals
• String Literal is a sequence of characters that can be a
combination of letters, numbers and special symbols,
enclosed in quotation marks, single, double or triple(“ “ or ‘ ‘
or “’ ‘”).
Special Literals
• None, which means nothing (no value).
X = None
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
Here, a, b, c are operands and operators are
= and + which are performing differently.
Types of Operators
• Python supports following types of operators -
– Unary Operator
• Unary plus (+)
• Unary Minus (-)
• Bitwise complement (~)
• Logical Negation (not)
– Binary Operator
• Arithmetic operator (+, -, *, /, %, **, //)
• Relational Operator(<, >, <=, >=, ==, != )
• Logical Operator (and, or)
• Assigment Operator (=, /=, +=, -=, *=, %=, **=, //=)
• Bitwise Operator (& bitwise and, ^ bitwise xor, | bitwise or)
• Shift operator (<< shift left, >> shift right)
• Identity Operator (is, is not)
• Membership Operator (in, not in)
Punctuators
• In Python, punctuators are used to construct
the program and to make balance between
instructions and statements. Punctuators
have their own syntactic and semantic
significance.
Comments
Function
Statements
Block
Indentation
Function Calling
A Python Program Structure
• As we have seen in previous slides, a
program contains following compnents-
– Expressions like a+b, a>b etc.
– Statements like a=10, c=a+b etc.
– Comments, lines starting with #.
– Function, block starting with def keyword
– Blocks and indentation like if and else blocks