3.data Handling
3.data Handling
➢ int
➢ float
➢ complex
Example:
w=1 # int
y = 2.8 # float
z = 1j # complex
2. Sequences
RESULT
OPERATOR NAME SYNTAX
(X=14, Y=4)
+ Addition x+y 18
_ Subtraction x–y 10
* Multiplication x*y 56
// Division (floor) x // y 3
% Modulus x%y 2
Page 2
ii. Relational Operators: Relational operators compare the values. It either
returns True or False according to the condition.
RESULT
OPERATOR NAME SYNTAX
(IF X=16, Y=42)
False
> Greater than x>y
True
< Less than x<y
False
== Equal to x == y
True
!= Not equal to x != y
False
>= Greater than or equal to x >= y
True
<= Less than or equal to x <= y
iii. Logical operators: Logical operators perform Logical AND, Logical OR and Logical
NOT operations.
Truth Tables
X Y X and Y
False False False
False True False
True False False
True True True
Page 3
X Y X or Y
X not X
False False False
False True
False True True
True False
True False True
True True True
DESCRIPTION SYNTAX
OPERA
TOR
Assign value of right side of expression to left side operand x=y
=
+z
Add AND: Add right side operand with left side operand and a+=b
+=
then assign to left operand a=a+b
Subtract AND: Subtract right operand from left operand and a-=b
-=
then assign to left operand a=a- b
Multiply AND: Multiply right operand with left operand and a*=b
*=
then assign to left operand a=a*b
Divide AND: Divide left operand with right operand and then a/=b
/=
assign to left operand a=a/b
Modulus AND: Takes modulus using left and right operands and a%=b
%=
assign result to left operand a=a%
b
Divide(floor) AND: Divide left operand with right operand and a//=b
//=
then assign the value(floor) to left operand a=a//b
Page 4
Exponent AND: Calculate exponent(raise power) value using a**=b
**=
operands and assign value to left operand a=a**b
Note:For operators with equal precedence, the expression is evaluated from left to right.
** Exponent -Right to Left
Order of Operator Description
Precedence
1 ( ), { } Parentheses (grouping)
2 ** Exponent
3 +x, -x Positive, negative
4 *, /, % Product, division, remainder
5 +, – Addition, subtraction
6 <=, <, >, >= Comparisons
7 =, %=, /=, += Assignment
8 not Boolean NOT
9 and Boolean AND
10 or Boolean OR
Expressions
An expression is defined as a combination of constants, variables, and operators.
An expression always evaluates to a value.. Some examples of valid expressions
are given below.
(i) 3.0 + 3.14 (ii) 23//3 -5 * 7 +14 -2 (iii) "Global" + "Citizen"
Evaluate the following expressions:
1. 12+3*4-6/2 = 12+ 12- 3.0= 21.0
2. (12+3)*4- 6/2
3. 12+3*(4-6)/2
4. 12*3%5+2*6//4
5. 12+ (3*4-6)/3
6. (2+3)**2 - 6/2
Page 5