Python Programming: Reema Thareja
Python Programming: Reema Thareja
Python Programming
Using Problem Solving Approach
Reema Thareja
Example:
10
Example:
11
Example:
13
14
15
Example:
16
Example:
17
18
19
20
21
22
Identity Operators
is Operator: Returns true if operands or values on both sides of the operator point to the same object and false
otherwise. For example, if a is b returns 1, if id(a) is same as id(b).
is not Operator: Returns true if operands or values on both sides of the operator does not point to the same object
24
and false otherwise. For example, if a is not b returns 1, if id(a) is not same as id(b).
© OXFORD UNIVERSITY PRESS 2017. ALL RIGHTS RESERVED.
Expressions
An expression is any legal combination of symbols (like variables, constants and operators) that represents a value. In
Python, an expression must have at least one operand (variable or constant) and can have one or more operators. On
evaluating an expression, we get a value. Operand is the value on which operator is applied.
Constant Expressions: One that involves only constants. Example: 8 + 9 – 2
Integral Expressions: One that produces an integer result after evaluating the expression. Example:
a = 10
• Floating Point Expressions: One that produces floating point results. Example: a * b / 2
• Relational Expressions: One that returns either true or false value. Example: c = a>b
• Logical Expressions: One that combines two or more relational expressions and returns a value as True or False.
Example: a>b && y! = 0
• Bitwise Expressions: One that manipulates data at bit level. Example: x = y&z
25
Examples
:
26
27
28
Examples
:
29
Example:
30
31
32