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

Python Operators — Python for Network Engineer

Uploaded by

AJAY KUMAR
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)
5 views

Python Operators — Python for Network Engineer

Uploaded by

AJAY KUMAR
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

Python Operators

Contents
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Identity Operators
Membership Operators

Operators in Python are used to perform operations on variables


and values. They are divided into the following groups:

Arithmetic operators
Assignment operators
Comparison operators
Logical operators
Identity operators
Membership operators

stable
Arithmetic Operators
Arithmetic operators are used with numeric values to perform
common mathematical operations.

Syntax Description Example

+ Addition 3+4

- Subtraction 1-5

* Multiplication 5*6

/ Division 7/2

% Modulus 5%1

** Exponentiation 8 ** 3

// Floor division 3 // 8

Assignment Operators
Assignment operators are used to assign values to variables.

stable
Syntax 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

Comparison Operators
Comparison operators are used to compare two or more variables.

Print to PDF stable


Syntax Description Example

== Equal x == y

!= Not equal x != y

> Greater than x>y

< Less than x<y

>= Greater than or equal to x >= y

<= Less than or equal to x <= y

Logical Operators
Logical operators are used to combine conditional statements.

Syntax Description Example

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


are true

or Returns True if one of the x < 5 or x < 4


statements is true

not Reverses the result not(x < 5 and x <


10)
stable
Identity Operators
Identity operators compare the memory locations of two objects.

Syntax Description Example

is Returns True if both variables are the same x is y


object

is not Returns True if both variables are not the x is not y


same object

Membership Operators
Membership operators test if a sequence is present in an object.

Syntax 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


specified value is not present in the object y

stable

You might also like