Python Operators — Python for Network Engineer
Python Operators — Python for Network Engineer
Contents
Arithmetic Operators
Assignment Operators
Comparison Operators
Logical Operators
Identity Operators
Membership Operators
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.
+ 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.
== Equal x == y
!= Not equal x != y
Logical Operators
Logical operators are used to combine conditional statements.
Membership Operators
Membership operators test if a sequence is present in an object.
stable