# Python Operators

Click to rate this post!
[Total: 0 Average: 0]

Operators are functions that perform some logical calculations. In other words, these are the constructs that manipulate the value of the operands. Python supports several kinds of operators. let us discuss one –by – one in detailed. Arithmetic operators :

Arithmetic operators are used for Addition, subtraction, multiplication and division and so on. Let us discuss them with an example.

Let us consider the operator with A =100 , B = 200

 Operator Description Example Addition(+) Add values on either side of the operator A+B =300 Subtraction(-) Subtracts A from B B-A =100 Multiplication(*) Multiplies A with B A*B = 2000 Division(/) Divides the denominator with numerator B/A =2 Modulo(%) Performs the division operator and returns the remainder B%A=0 Exponent(**) Performs exponential calculation on operators A**B= 100 power 200

#### Relational / comparison operator :

These operator compares the operands and displays the result.

Let us assume a = 3 , b =5

 Operator Description Example == This operation returns true if two values are equal A ==B  returns False != If the two operations are not equal  this returns true A!=B returns true If the value of the left operand is greater than right this returns true A>B returns false < This operator true if the left operand is less than the right operand A< B returns true >= This operator returns true if the left operand is greater than or equal to the right operand A>=B returns false <= This operator returns true if the left operand  is less than or equal to the right operand A<=B returns True

Visit Online courses  for more live examples

#### Assignment operator :

An assignment operator is used to assign a new value to the variable.

Let us assume a =5 , B = 10

 Operator Description Example = Assigns a value from right operand to left operand C= a+b assigns the value of the sum of A and B to c += ADD and It adds right operand to the left operand and assigns the result to the left operand C+=a  is equivalent to c= c+a -=Sub and It subtracts right operand from the left operand and assigns the results to the left operand C-=a is equivalent to  c = c –a *=Multiply and It multiplies right operand with left operand and assigns the  result to the left operand C*=a is equivalent to c = c*a /= division and It divides the left operand with the right operand and assigns the result to the left  operand C/=a is equivalent to c = c/a %= Modulo and It performs modulus of the two operands and assigns the result to left operand %=a  is equivalent to c= c%a **=Exponent And It performs an exponential calculation on two operands and assigns the value to the left operand c**=a is equivalent to c = c**a

Visit Python Training for more code examples

#### Bit-wise operators :

Every operation that needs to perform must divide into bits. And performs the operation and displays the result in the decimal format. Let us discuss with an example A =30, B= 23

These two numbers written in binary format as

A = 30 = 0001 1110, B = 23 = 0001 0111.

 Operator Description Example And (&) If both the inputs are 1 ‘s the result is 1 else the result is zero A&B  =22 (0001 0110) Or(|) If both the inputs are 0’s the result is zero else the result is 1 A|B= 31(0001 1111) Xor(^) If both the bits are same the result is 0 else the result is 1 A^B =9(0000 1001) Compliment(~) If the input is one the output is zero and vice-versa A~B =-31(1000 1111) Binary left shift (<<) The left operands are move left by the number of bits specified by the right operand A<<2 = 120(0111 1000) Binary right shift(>>) The right operands are moved right but the number of bits specified by the right operand A>>2 =(0000 0111)

#### Logical operators :

Logical operators are used the logic condition ( true (or) false). We have three types of logical operators. Let a = 5 , b=10, c =20

 Operator Description Example And True  only if both the inputs are one ac returns false Or True if any one of the input is one ac  returns true a>b and a>c returns false Not It negates the input a

Will Python replace java or not let’s check here.

#### Membership operator :

The membership operators are classified into two types.

A={1 ,2,3,4,5}

 Operator Description Example Is It returns true if the value is found in the sequence 5 in A returns True 10 in A returns False Not in True if the variable is not found in the sequence 5 not in A returns False 10 not in A returns True
##### Identity operators :

It compares the objects memory address

A =100 , B =100

 Operator Description Example Is Returns true if the operands identity is same A is B returns True Is not Returns true if the operand identity is not the same A is not B returns false

#### Operator precedence :

When there is several operations to be performed, operator precedence determines which operator would be given importance over others.

**

~+/~-

*/%//

+-

>><<

&

^|

<=< >>=

<>==!=

= -= +=//=%=/=*=*==

Is isnot

In innot

Not or and

Note :

we can expect a question in Operator precedence in  online certificate courses

Subscribe

Drop Us A Query

Trending Courses
• Microsoft Azure Architect Technologies(AZ-300) • Azure is a great Microsoft Cloud Computing platform in providing various cloud services through online. ITGuru Certified Azure Architect certification course gives you the practical knowledge on Azure Cloud platform through real-world use cases from live experts

• ServiceNow Admin Training • Getting knowledge of cloud platforms like ServiceNow is essential in today’s world for the smooth running of projects in cloud platform. Turn your dream to the reality of becoming the Certified ServiceNow Administrator through ServiceNow Administration online certification Course with practical examples by live industry experts through online at ITGuru with real-world use cases.

• Workday Financials Training • knowing the basics on any platform like Workday is not enough to sustain the IT industry. Hence it is essential to go beyond on Workday basics like Workday Financials training which lets you know the application of Financials management in real -world use cases from ITGuru Live Experts in a practical way.

• Workday Training • An organization is considered as the best one when it offers the best benefits to the employee. Moreover, the greater the employee benefits, the greater the contribution to the organization. ITGuru let you know the practical workday Human Resource Management(HRM) features with live examples by experts

• Python Online Course • Turn your dream into reality by ITGuru live experts with real-world use cases through practical knowledge on python online course and become the certified associate in python programming and become a master in python programming

• Python Programming • Python is the trending programming language in the IT industry. Mastering in python programming gives you more value among the people in the IT industry. Hence start today to learn python programming online by live experts with real-time uses cases at ITGuru

100% Secure Payments. All major credit & debit cards accepted. Call Now Button