Operators in Python | Arithmetic Operators and Comparison/Relational Operators

 


Operators in Python

Operators

Operators are those who performs some specific operation. Python has a wide variety of operators.

In the simple language Operators are used to perform operations on variables and values.

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

Example:

Print(10+5)

The various python operators are categorized into:

  1. Arithmetic operators
  2. Comparison/Relational Operators
  3. Assignment 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:

Considering a=10 and b=5

Operator

Name

Description

Example

+

Addition

Add two or more numbers

a+b = 15

-

Subtraction

Subtracts two or more numbers

a-b = 5

*

Multiplication

Multiply two or more numbers

a*b = 50

/

Division

Divide two numbers

a/b = 2

%

Modulus

Give the remainder after dividing first number with second

a%b = 0

**

Exponent

Return exponential (Power) value

a**2 = 100

//

Floor division

Divides tow numbers but gives the quotient but removes the decimal place.

But in case of Negative value it floors the number to far from zero.

a//b = 2

Comparison Operators

Comparison/Relational operators are used to compare two values that performs comparison among operands. It gives either true or false based on the condition. Comparison/Relational operators are:

Considering a=10 & b=5

Operator

Name

Description

Example

==

Equal

Check whether the first number is equal to second number

a==b returns false

!= Or <>

Not equal

Check whether the first number is not equal to second number

a!=b returns true

a<>b returns true

> 

Greater than

Checks whether first number is greater than second

a>b  returns true

< 

Less than

Checks whether first number is smaller than second.

a<b returns false

>=

Greater than or equal to

Checks whether first number is greater than or equal to second number or not

a>=b returns true

<=

Less than or equal to

Checks whether first number is smaller than or equal to second number or not

a<=b returns false


<<Previous                                                  Next>>

कोई टिप्पणी नहीं

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click

Send Multiple Emails From Excel | Send Bulk Mail from Excel Sheet with Attachment in One Click Download VBA Code Notepad file - Click here D...

Blogger द्वारा संचालित.