Working with operators in Python

Desira Wijesundara
4 min readMay 1, 2019

I’ll try my best to get this through to you as simply as humanly possible. Although I assume, you have some knowledge beforehand about this programming gig, let alone Python.

What are operators used for?

Simply put, to control and manage data inside an application, but if you want to go further down operators are used to define how one piece of data is compared to another piece of data as well as to modify information within a single variable. For an operator to work, you must provide it with a variable or an expression. A variable works as a data storage, while an expression is a mathematical formula, making operators much more effective with math related tasks.

Defining operators;

Just as a real life telephone operator takes input from a caller, discuss how they wish to be aided and forwards them to whom they wish to speak, operators in terms of Python have a similar role; taking input in the form of variable or expressions, executing a desired task (in most cases math related) and spitting out the output. The factors that are provided to the operator as input are called operands. Find below the categories of operators that are used in Python.

Unary; Requires a single variable or expression as input, and often used in decision-making processes.

Arithmetic; Provides access to Pythons’ math library. The arsenal consists of elementary arithmetic operations (addition, subtraction, multiplication and division) as well as complex operations, giving you increased versatility when it comes to writing code.

Relational; Confirms whether the relationship you’ve provided agrees with two values, by comparing them. The truth value (true or false) of these operators are highly useful to guarantee if an applications’ condition is sufficient enough to complete the tasks it sets out to do.

Logical; Combines the true or false value of variables or expressions provided, so that you can evaluate their truth value. These operators are used to create Boolean (1 or 0) expressions, which are then used to decide whether to perform a task or not inside an application.

Bitwise; Interacts with every bit which the number is made of, and counts ‘0’ as a false value and ‘1’ as a truth value.

Assignment; Assigns a value to a variable, and mostly used to perform mathematical operations.

Membership; Clarifies whether a certain value exists within a database or not by giving out a truth value.


When given a certain class name this operator identifies and confirms whether a certain value or an expression belongs to a certain class, by giving out a truth value. Helps to ensure you are working with the correct information, to avoid further errors.

Now you know the operator types, but do you know who is in charge when it comes to working with multiple operators? The following table is the ranking of the operators according to their priority.

Now off you go, code. Cheers!