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

Operator

Uploaded by

Jesica D'cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Operator

Uploaded by

Jesica D'cruz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Programming with Python

Types of Operator
Major operators supported by Python are
• Arithmetic Operators
• Assignment Operators
• Comparison (Relational) Operators
• Logical Operator
• Membership Operators

Arithmetic Operators
Operator Operation Example Evaluates to
..
** Exponent 2 ** 3 8
% Modulus/remainder 22 % 8 6
// Integer 22//8 2
division/floored
Quotient
/ Division 22/8 2.75
* Multiplication 3*5 15
+ Addition 3+5 8
- Subtraction 5-3 2

1 Maya Nair
Programming with Python

Assignment Operators

Operator Example Same As

= x=5 x=5

+= x += 3 x=x+3

-= x -= 3 x=x-3

*= x *= 3 x=x*3

/= x /= 3 x=x/3

%= x %= 3 x=x%3

//= x //= 3 x = x // 3

**= x **= 3 x = x ** 3

2 Maya Nair
Programming with Python

Comparison Operator
Operator Name Example

== Equal x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y

>= Greater than or equal x >= y


to
<= Less than or equal to x <= y

3 Maya Nair
Programming with Python

Logical Operators
Operator Description Example

and Returns True if both x < 5 and x < 10


statements are true
or Returns True if one of x < 5 or x < 4
the statements is true
not Reverse the result, not(x < 5 and x <
returns False if the result 10)
is true

Membership Operators

Operator Description Example

in Returns True if a sequence with the x in y


specified value is present in the
object

not in Returns True if a sequence with the x not in y


specified value is not present in the
object

4 Maya Nair
Programming with Python

Operator Precedence in Python


Sr No Operator
1 ** (Exponentiation)
2 ~ (Complement)
3 *, /, %, // Multiply,
divide, modulo and
floordivision
4 +,- (Addition and
subtraction)
5 <=, <, >=,> (Comparison
operators)
6 <> ,==,!= (Equality
operators)
7 =, %=, /=, //= ,-=, +=,
*=,**= (Assignment
operators)
8 in, not in ( Membership
operators)
9 not, or, and (Logical
operators)

5 Maya Nair

You might also like