Top Ad unit 728 × 90

Libreoffice

Libreoffice Writer

Types of Python Operators

 


Python Operators


Operators are used to perform operations on variables and values.


In the example below, we use the + operator to add together two values:


Python divides the operators in the following groups:


1. Arithmetic operators

2. Assignment operators

3. Comparison operators

4. Logical operators

5. Identity operators

6. Membership operators

7. Bitwise operators



Arithmetic operators


Arithmetic operators are used with numeric values to perform common mathematical operations:


+, -, ×, /, %(Remainder), **(Exponent) or (Square and Cube), //(Floor Division) or (Ans Integer). 




Operator

Name

Example

+

Addition

x + y

-

Subtraction

x - y

*

Multiplication

x * y

/

Division

x / y

%

Modulus

x % y

**

Exponentiation

x ** y

//

Floor division

x // y




Assignment Operators


Assignment operators are used to assign values to variables:


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

&=

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

:=

print(x := 3)

x = 3
print(x)

 

Types of Python Operators Reviewed by ADcomputercampus on September 07, 2024 Rating: 5

No comments:

Contact Form

Name

Email *

Message *

Powered by Blogger.