Python - Slide1
Python - Slide1
using
Computers
(BCAC0018) Module II
Course: BCA I Year I Semester
By: Dr Aditya Saxena
Assistant Professor
Computer Engineering & Applications
Department,
GLAUniversity, Mathura
Topic
s
• Operators in
Python
– Arithmetic + - / % **
Operators * //
– Relational < == ! >= <=
Operators > =
– Assignment =
Operator
– Bitwise Operators & ~ < >>
– Logical Operators ^ <
| or not
and
– Membership in not in
Operators
– Identity Operators is is not
Arithmetic
Operators
+- *
Let a and b are operand
• If a and b both are int the result will
beint
• If a and b both are float the result will be float
• If in a b, one of them is float, result
will be float
Arithmetic
Operators
+ +
can be applied on Numbers, List,
Tuple, String
Arithmetic
-
Operators
- can be applied on
Numbers only
Arithmetic
Operators
*
* can be applied on Numbers, and
between
int and string,
int and list,
int and tuple
Arithmetic
Operators
/
True division
Result is an int
Arithmetic
Operators
**
Exponent
Multiple assignments
>>>a, b, c = 5, 3.2,
"Hello"
>>>x = y = z = 100
Assignment
Operator
Compound =
assignment
>>>a += 5
>>>a = a+5
Bitwise Operators AND (&) and OR(|)
>>>x = 5 #10
>>>y = 7 1
#11
>>>x & y 1
5
>>>x | y
7
• expr1 or
expr2
• expr not
Membership Operators
in not in
syntax: var in
iterable_object
>>>x=5
>>>y=[1,2,3,5
,6,7]
>>>x
in y
True
>>>x not
in y False
Identity Operators is is not
>>>a=10
>>>b=10
>>>a is b True
>>>x=500
>>>y=500
>>>x is not y
False
Ternary Operator
The ternary operator in Python allows you to write a simp
le one-
line conditional statement. Here's a quick example: