0% found this document useful (0 votes)
11 views

Python - Slide1

Introduction

Uploaded by

aditya.2352700
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Python - Slide1

Introduction

Uploaded by

aditya.2352700
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Problem Solving

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

Applied on numbers only

Let a and b are operand


• If a and b both are int or float or one of
them is float, result will be float
Arithmetic
Operators
//
Floor division or truncated division

Can be applied on int and float only

Let a and b are operand


• If a and b both are int the result will be
int
• 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
%
Modulus or Remainder Operator

Can be applied on int

Result is an int
Arithmetic
Operators
**
Exponent

Can be applied on numbers

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
Relational Operators
< > == != >=
<=
• Returns
• True
Can be applied
or on Numbers and
False
String
Assignment
Operator =
Variable assignment
a=5
b = 3.2
c = "Hello"

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

Check binary equivalent of a number in python = bin(num)[2:]


Bitwise Not (~) and XOR (^)
>>>x = 5 #10
>>>y = 7 1
#11
>>> ~x 1
#1’s complement
-6 # -(101+1) => - (110)
=> -6
>>>x
^y 2 # 010
Logical Operators and or
not
• expr1 and
expr2

• 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:

You might also like