Urgenthomework logo
UrgentHomeWork
Live chat

Loading..

Basic Operators in Python Help

Operations in Python

In this tutorial we will be focusing on the operations which we can perform in Python.

Some of the operators that are present in python are:

a) Comparison

b) Logical

c) Arithmetic

d) Assignment

e) Bitwise

We shall be looking upon each of these operations in detail in this tutorial.

Let us start with relational operators

The comparison operators are used to compare the values of two or more values or statements. These are binary operators that is can only be used in case of two variables.

The signs included are:

1) Greater than (>): used to check which number is greater if we are comparing two elements or operands. Example 20>10. It will return true only when one number is greater than the other.

2) Less than (<): used to check that out of the two numbers/operands which one is smaller. Example 7<9. It will return true only when one number is less than the other number.

3) Greater than equal to (>=): used to check whether one number out of two is greater than or equal to the other in terms of value. Example 8>=8. It will return true when one number is greater or equal to the other.

4) Less than equal to (<=): used to check whether one of the two numbers is less than or equal to the other. Example 10<=11. It will return true when one number is less or equal to the other number.

5) Double equal to (==): it is used when we want to check whether the two elements are equal by value. Example 17==17. It will return true when both the values are equal.

6) Not equal to (! =): used when we want to check the inequality of two numbers that is, if the numbers are equal by value or not. Example 43! =43. It will return true when the two numbers are not equal by value.

Logical operators are used when we want to get a result by checking two conditions like if we want our result to satisfy both the conditions, then we will use the “and” operator.

If we want our condition to fulfill at least one of the two requirements, then we will be using the “or” operator.

The last logical operator is the not operator. It gives the opposite of the condition, that is, if you want true as outcome then you need to give not false.

Python Homework Help

In the above program, we have used and, or, not operators.

Let us now have a look at the arithmetic operators.

The arithmetic operators are +(addition), -(subtraction), *(multiplication), /(division), %(modulus), **(exponent), //(floor division).

Python Homework Help

Here we have performed all the operations.

The “**” operator is used to calculate the exponential power of a number given as a**b which means a to the power b.

Let us now jump onto assignment operator.

a) “=” assigns the value of the right-side values to the left side value (r = t - y)

b) “+=” adds the value of the left and right operand and assigns it to the left operand (v+=g, v = v + g).

c) “-=” subtracts the value of the right-side operand from the left side operand and stores the value in the left side operator (e - = t, e= e - t).

d) “*=” multiplies the value of the left and right operand and assigns it to the left operand (e*= g, e= e*g).

e) “/=” divides the value of the left operand by the right operand and assigns it to the left operand (d/=y, d= d/y)

Let us look at the bitwise operator.

The bitwise operator works on the bits and perform operations bit by bit that is, binary operations.

Python Homework Help

That is all for this tutorial, I hope that you learnt something from it. Do not forget to practice whatever you have learned till now as it will wash out of your head if you would not practice.

Copyright © 2009-2023 UrgentHomework.com, All right reserved.