Aurthomatic operation in Python part 18 | operations such as addition, subtraction, multiplication and division.

Arithmetic operations such as addition, subtraction, multiplication and division





Original operator in python
Arithmetic operators: Arithmetic operators are used to perform mathematical operations such as addition, subtraction, multiplication and division.
Operator Description SYNTAX
+ Add: adds two operands x + y
- subtraction: subtract two operands x - y
* Multiplication: Multiply two operands x * y
/ Division (float): divides the first operator by the second x / y
// division (floor): divides the first operand by the second x // y
% Modulus: Remains the remainder when the first operand is divided by the second x% y
filter_none
Edit
play_arrow

brightness_4
# Examples of arithmetic operators
a = ९
B = ४

# Sum of numbers
Sum = A + B
# Subtraction of numbers
Sub = a - b
# Multiplication of numbers
mul = a * b
# Division of number (float)
div1 = A / B
# Of numbers (floor)
div2 = A / B
# Modulo of both numbers
mod = a% b

# Print result
Print (add)
Print (sub)
Print (mul)
Print (div1)
Print (DIV2)
Print (modern)

Output:


13
5
36
2.25
2
1


Relational operators: Relational operators compare values. This is either true or false according to the situation.
Operator Description SYNTAX
> Greater than: true if left operand is greater than right x> y
<Less than: If the left open is correct then the right is less than x <y
== Equivalent: True if both operations are equal x == y
! = Not equal to - true if operations are not equal x! = Y
> = Greater than or equal to: True if the left operand is greater than or equal to the right x = = y
<= Less than or equal to: This is true if the left operand is less than or equal to the right x <= y
filter_none
Edit
play_arrow

brightness_4
# Examples of Relational Operators
a = 13
B = 33

# A> B is wrong
Print (A> B)

# A <B is true
Print (<b)

#A == B is wrong
Print (a == b)

# a! = b is true
Print (a! = B)

# A> = B is incorrect
Print (a> = b)

# A = B is true
Print (a <= b)

Output:


false
truth
false
truth
false
truth


Logical operators: Logical operators perform logical end, logical or logical operations.


Operator Description SYNTAX
And logical and: true if both operands are true x and y
Or logical or: true if either one letter x or y is true
Not logical: true if the operand is false not x
filter_none
Edit
play_arrow

brightness_4
# Examples of logical operators
a = true
B = False

# A and B print is incorrect
Print (A and B)

# A or B is correct
Print (or a b)

#Printnot a falls
Print (no)

Output:


false
truth
false


Bitwise operator: Bitwise operators work on bit and bit by bit operation.
Operator Description SYNTAX
& Bitwise and x & y
| Bitwise or x | y
~ No bitwise ~ x
^ Bitwise XOR x ^ y
>> bitwise right shift x >>
<< bitcoin left shift x <<
filter_none
Edit
play_arrow

brightness_4
# Examples of bitwise operators
a = 10
B = 4

# Print bitwise and operation
Print (a & b)

#Bitwise or print operations
Print (a | b)

# Not print bitwise operation
Print (~ a)

# Print bitwise XOR operation
Print (^ b)

# Print bitwise right shift operation
Print (>> 2)

# Print bitwise left shift operation
Print (<< 2)

Output:


0
14
-1 1
14
2
40


Assignment operator: Assignment operators are used to assign values ​​to variables.



Operator Description SYNTAX

= Specify the value to the right of the expression for the left hand operand x = y + z
+ = Add and: Add the right side operand with the left side operand and then assign the left operand a = = b a + a b
- = subtract and drop: subtract the right operand from the left operand and then assign to the left operand - a = = b a-b-b
* - Multiply and: Multiply the right operand with the left operand and then assign the left operand a = = b a * * b
/ = Split and: Split the left operand with the right operand and then assign the left operand to a / = b a = a / b
% = Modulus and: takes the modulus using the left and right operands and returns the result in the left operand% = b = a% b
// = divide (floor) and: divide left operand by right operand and then assign left operand to value (floor) a = = b a = b
** = Exponent and: Calculate the exponent (increase power) value using the operators and assign the value to the left operator ** a = b = a ** b
Works on bit = and operands and assigns values ​​to left operands a and = b a = b
| = Acts on bitwise or operands and assigns values ​​to left operands a = = b a = a | b |
^ = Bitwise xOR on the operand and assigns a value to the left operand a = = b a ^ b
>> = Shifts the bitwise right on the operand and assigns a value to the left operand a = = b a = a b
<< = Performs bitwise left operations and assigns values ​​to the left operand a << = b a a << b


Special Operators: Some special types of operators are-
Identity operator
The is and is not identifiers are both used to check if two values ​​are located on the same part of memory. Two variables that are the same do not mean that they are the same.
This is true if the operands are the same
This is not true if the operands are not equal
filter_none
Edit
play_arrow

brightness_4

Post a Comment

1 Comments

Unknown said…
Usually I never comment on blogs but your article is so convincing that I never stop myself to say something about it. You’re doing a great job Man learn Python Online Course

Search This Blog