Python Chapter 2 Notes by Ur Engineering Friend
Python Chapter 2 Notes by Ur Engineering Friend
Python Chapter 2 Notes by Ur Engineering Friend
Notes
Operators:
Arithmetic operators
Assignment operators ( not useful for MSBTE )
Relational operators
Logical operators
Identity operators
Membership operators ( will discuss in list and tuples topic )
Bitwise operators ( not for MSBTE )
Relational Operators:
Identity Operators:
Conditional Statement
1. IF
2. IF...ELSE
3. Nested IF
IF Statement :
If ( condition ) :
Statements...
......................
IF Else :
It contains a body of code which runs only when the condition given in the if
statement is true. If the condition is false, then the optional else statement runs
which contains some code for the else condition.
if expression
Statement
else
Statement
Any number of these statements can be nested inside one another. Indentation is
the only way to figure out the level of nesting. They can get confusing, so they
must be avoided unless necessary.
If ( condition ):
If ( condition ):
Statement
1. While Loop:
2. In python, while loop is used to execute a block of statements repeatedly
until a given a condition is satisfied. And when the condition becomes
false, the line immediately after the loop in program is executed.
Syntax :
while expression:
statement(s)
3. All the statements indented by the same number of character spaces after
a programming construct are considered to be part of a single block of
code. Python uses indentation as its method of grouping statements.
For Loop
The for loop in Python is used to iterate over a sequence or other iterable
objects. Iterating over a sequence is called traversal.
Loop continues until we reach the last item in the sequence. The body of for
loop is separated from the rest of the code using indentation.