Page 164 - Computer Science Class 11 With Functions
P. 164
is not It yields True if the operands on either side >>> type(b) is not int
of the operator are different objects or False
different types, and False otherwise. >>> type(c) is not list
True
>>> a is not b
True
>>> a = b
>>> a is not b
False
7.5.6 Membership Operators
These operators are used to check whether a particular value is a member of a given sequence and return either True
or False.
Table 7.6: Membership Operators
Operator Explanation Examples
in The expression a in b yields True >>> myList = [0, -4, 5, 8, 10, 50, 4]
if the object a is included in b and >>> 5 in myList
False otherwise. True
>>> 100 in myList
False
not in The expression a not in b yields >>> myList = [0, -4, 5, 8, 10, 50, 4]
True if the object a is not included in >>> 5 not in myList
b and False otherwise. False
>>> 100 not in myList
True
7.6 Expressions
An expression in Python is a valid combination of constants, variables, and operators. A single value of any type
or the name of an object (i.e. a variable) are examples of the simplest expressions. On evaluation, an expression
yields a value. The type of an expression is based on the types of operators and operands that are used in it. An
expression yields a value, and the type of the value that an expression yields is called the type of the expression.
Assuming that the variables a, b, and num have values 5, 7, and 12.5 respectively, some examples of valid
expressions are:
Expression Type
(i) 50 int
(ii) a int
(iii) a == 5 and b>0 bool
(iv) num + 45.6 - 6 float
(v) 22/7*2*2 float
(vi) "abc"*3 str
7.7 Precedence of Operators in Python
When an expression involves multiple operators, Python resolves the order of execution according to the precedence
of operators. An operator with higher precedence will be evaluated before an operator with lower precedence. As
a general rule, the unary operators have higher precedence over binary operators. Among the binary operators, the
table gives the precedence from highest to lowest.
162 Touchpad Computer Science-XI

