Professional Documents
Culture Documents
Unit-2 Operators, Decision Making and Loops
Unit-2 Operators, Decision Making and Loops
Operators, Decision
Making and Loops
Prepared By:-
Prof. Chaitanya Kale
Types of Operators
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Arithmetic Operators
• Arithmetic operators are used with numeric values to perform
common mathematical operations:
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Assignment Operators
• Assignment operators are used to assign values to variables:
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Comparison Operators
• Comparison operators are used to compare two values:
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Logical Operators
• Logical operators are used to combine conditional statements:
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Identity Operators
• Identity operators are used to compare the objects, not if they are
equal, but if they are actually the same object, with the same
memory location:
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Membership Operators
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Bitwise Operators
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python If ... Else
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python If ... Else
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
if statement
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Elif Statement
The elif keyword is pythons way of saying "if the previous conditions
were not true, then try this condition“.
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Else Statement
The else keyword catches anything which isn't caught by the preceding
conditions.
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Nested If Statement
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Loops
• Python has two primitive loop commands:
– while loops
– for loops
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
While Loop
With the while loop we can execute a set of statements as long as
a condition is true.
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
The continue Statement
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python For Loops
• A for loop is used for iterating over a sequence (that is either a list, a
tuple, a dictionary, a set, or a string).
• This is less like the for keyword in other programming languages, and
works more like an iterator method as found in other object-orientated
programming languages.
• With the for loop we can execute a set of statements, once for each
item in a list, tuple, set etc.
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python For Loops Example
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
For loop Using range() function
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
For loop Using range() function
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python break statement
• The break is a keyword in python which is used to bring the
program control out of the loop.
• The break statement breaks the loops one by one, i.e., in the case of
nested loops, it breaks the inner loop first and then proceeds to
outer loops.
• In other words, we can say that break is used to abort the current
execution of the program and the control goes to the next line after
the loop.
• The break is commonly used in the cases where we need to break
the loop for a given condition.
• The syntax of the break is given below
– #loop statements
– break;
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python break statement Example
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
Python Pass Statement
In Python, the pass keyword is used to execute nothing; it means,
when we don't want to execute code, the pass can be used to execute
empty. It is the same as the name refers to. It just makes the control to
pass by without executing any code. If we want to bypass any code
pass statement can be used.
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale
References
Unit-2 Operators, Decision Making and Loops Prepared by:- Prof. Chaitanya Kale