Real-Time Python Operators and Operator Precedence cheat sheet

Python Operators and its real-time usage:

Hello readers, welcome back to know the Python Operators and its real-time usage in the projects. These operators are mainly used in the Data Analytics and Numerical programs. Let us see how many Python Operators exist and their use.

As in all programming languages, in Python also have the so-called operators. An operator is basically a symbol that we use in expressions like “1 + 3” where 1 and 3 would be operands and “+” is the operator. There are different types of operators like Arithmetic, Assignment, Relational, Logical, Bitwise and Identity operators.

Arithmetic Operators:

The arithmetic operators are the simplest of all, they are used to perform basic arithmetic operations, that is, addition, subtraction, multiplication division, module / residual, and exponential.

The following assumptions variable a is 10, b is variable 20:

Operators Description Examples Output
+ Plus – two objects are added a + b 30
Save – get a negative number is subtracted from another number or a – b -10
* Multiply – multiply two numbers or returns the string repeated several times a * b 200
/ In addition – x divided by y b / a 2
% Modulo – returns the division remainder b% a 0
** Power – returns x raised to the power of y a ** b 10 20th power, the output 100000000000000000000
// Take divisible – Returns the integer part of the quotient 9 // 2, 9.0 // 2.0 4, 4.0

Assignment Operators:

The assignment operators are used to basically assign a value to a variable, as well as when we use the “=”.

Operators Description Examples
= Equal to, is the simplest of all and assigns to the variable on the left side any variable or result on the right side. c = a + b, a + b operation will assign the result to c
+ = Addition assignment operator, adds to the variable on the left side the value on the right side c + = a is equivalent to c = c + a
– = Subtraction assignment operator, subtract the value on the right side from the variable on the left side. c – = a is equivalent to c = c – a
* = Multiplication assignment operator, multiply the value on the right side of the variable on the left side. equivalent to c * = a c = c * a
/ = Division assignment operator, divide the value on the right side of the variable on the left side. c / = a is equivalent to c = c / a
% = Modulo assignment operator c% = a is equivalent to c = c% a
** = Exponentiation assignment operator c ** = a is equivalent to c = c ** a
// = Take divisible assignment operator c // = a is equivalent to c = c // a

Relational Operators:

The Relational operators (Comparison operators) are used to evaluate expressions that can only have 2 results, these results are true or false (true or false) and are the following.

The following assumptions variable a is 10, b is variable 20:

Operators Description Examples
== Equal – compare objects for equality (A == b) returns False.
! = It is not equal – compare two objects are not equal (A! = B) returns true.
<> It is not equal – compare two objects are not equal (A <> b) returns true. This operator is similar to! =.
> Greater than – Returns whether x is greater than y (A> b) returns False.
< Less than – Returns whether x is less than y. All comparison operators return 1 for true and 0 for false. These respectively special variables True and False equivalence. Note that these variable name capitalization. (A <b) returns true.
> = Greater than or equal – Returns whether x is greater than or equal y. (A> = b) returns False.
<= Less than or equal – Returns whether x is less than or equal y. (A <= b) returns true.

The other Python Operators are written in the next article, Logical Operators, Bitwise Operators, and Identity Operators.
Click here to know the Operator Precedence Sheet.

Real-Time Python Operators and Operator Precedence cheat sheet
Rate this post

One Response - Add Comment

Reply