Chapter 1 Cls 12
Chapter 1 Cls 12
11 )
Python (a computer language)
• We know that Python is a powerful and high level language and it is an interpreted
language.
• Python gives us two modes of working-
– Interactive mode
– Script mode
ScriptMode
Interactive
Mode
Python (Limitations)
There are few limitations in Python which can be neglected because of its
vast usage.
• It is not a Fast Language.
• Libraries are very less.
• It is week in Type binding.
• It is not easy to convert some other
language.
Tokens
• Token- is the smallest unit of any programming language.
Keywords::
• Keywords are those words which provide a special meaning to the interpreter.
• These are also known as reserve words. These can’t be used as identifiers variable name or
any other purpose.
– 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 “’ ‘”).
In python, string is of 2 types
Single line string
Text = “Hello World” or Text = ‘Hello World”
Multi line string
Text = ‘hello\ or Text = ‘’’hello
world’ word”
Numeric Literals
• Numeric values can be of three types -
CORE
DATA TYPE
Floating
Integer Complex String Tuple List Dictionary
Point
Boolean
• Mutable (Changeable)
lists, dictionaries and sets.
• Immutable (Non-Changeable)
• The symbols that shows a special behavior or action when applied to operands are called operators.
For ex- + , - , > , < etc.
• Python supports following operators-
I. Arithmetic Operator
II. Relation Operator
III. Identity Operators
IV. Logical Operators
V. Bitwise Operators
VI. Membership Operators
Operator Associativity
• In Python, if an expression or statement consists of multiple or more than one operator then operator
associativity will be followed from left-to- right.
• In above given expression, first 7*8 will be calculated as 56, then 56 will be divided by 5 and will
result into 11.2, then 11.2 again divided by 2 and will result into 5.0.
*Only in case of **, associativity will be followed from right-to-left.
if <condition>:
statement(s)
l
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Python---if-else Statements
If out of two statements, it is required to select one statement for processing on the basis of a condition,
if-else statement is to be used. Its syntax is-
if <condition>:
statement(s) when condition is true
else:
statement(s) when condition is false
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Nested If -else:
• for loop
• while loop
.
Range () Function
.
for <var> in <sequence>: statement1
while <test-condition>: statement1 if <condition>: break
if <condition>: break statement2
statement2 statement3
statement3 Statement4
Statement4 statement5
statement5
Jump Statements Break Statement
Output Output
.
in and not in operator
• in operator-
3 in [1,2,3,4] will return True.
• not in operator-
5 not in [1,2,3,4] will return True.
.
Jump Statements Continue Statement
.
Nested Loop
OUTPUT
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::