Page 430 - CITS - Computer Software Application -TT
P. 430
COMPUTER SOFTWARE APPLICATION - CITS
Example:
m = 70
n = 70
if ( m is not n ):
print(“Result: m and n have same identity”)
else:
print(“Result: m and n do not have same identity”)
Output: m and n do not have same identity
7 Membership Operators
We use membership operators to check whether a value or variable exists in a sequence (string, list, tuples, sets,
dictionary) or not. Python has two membership operators: in and not in. Both return a Boolean result. The result
of in operator is opposite to that of not in operator.
Example:
var = “TotalSach”
a = “s”
b = “tal”
c = “ac”
d = “Al”
print (a, “in”, var, “:”, a in var)
print (b, “not in”, var, “:”, b not in var)
print (c, “in”, var, “:”, c in var)
print (d, “not in”, var, “:”, d not in var)
Output:
s in TotalSach : True
tal not in TotalSach : False
ac in TotalSach : True
Al not in TotalSach : True
Conditional Statements
There are situations in real life when we need to make some decisions and based on these decisions, we decide
what we should do next. Similar situations arise in programming also where we need to make some decisions and
based on these decisions we will execute the next block of code.
Conditional statements in Python languages decide the direction(Control Flow) of the flow of program execution.
Types of Statements in Python
There are 4 types of Statements in Python...
1 The if statement
2 The if-else statement
3 The nested-if statement
4 The if-elif-else ladder
417
CITS : IT&ITES - Computer Software Application - Lesson 120 - 137 CITS : IT&ITES - Computer Software Application - Lesson 120 - 137