Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Follow publication

Member-only story

Mastering Python Operators and Expressions: From Arithmetic to Logic

B Kirankumar
Python in Plain English
5 min readSep 3, 2024

--

This article is Chapter 2 of “ Unlocking Python: Your Path from Beginner to Expert” series.

Operators and expressions are the core tools that allow you to perform calculations, manipulate data, and control the flow of your Python programs. Whether you’re adding numbers, comparing values, or creating complex logical conditions, understanding how operators work is essential. This article will walk you through the various types of operators in Python, demonstrating how they can be used to build powerful expressions.

What Are Operators?

In Python, operators are symbols or keywords that perform operations on variables and values. These operations can range from basic arithmetic to more complex logical evaluations. Operators are categorized based on the type of operation they perform.

Here’s a breakdown of the main types of operators in Python:

  1. Arithmetic Operators
  2. Comparison Operators
  3. Logical Operators
  4. Assignment Operators
  5. Bitwise Operators
  6. Identity and Membership Operators

Let’s explore each of these categories in detail.

1. Arithmetic Operators: Performing Calculations

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, and division. They are the most basic and frequently used operators in Python.

  • Addition (+): Adds two operands.
a = 10
b = 5
print(a + b) # Outputs: 15
  • Subtraction (-): Subtracts the right operand from the left.
print(a - b)  # Outputs: 5
  • Multiplication (*): Multiplies two operands.
print(a * b)  # Outputs: 50
  • Division (/): Divides the left operand by the right operand (returns a float).
print(a / b)  # Outputs: 2.0
  • Floor Division (//): Divides the left operand by the right operand and returns the largest integer smaller than or equal to the result.

--

--

Published in Python in Plain English

New Python content every day. Follow to join our 3.5M+ monthly readers.

Written by B Kirankumar

Hi there, am a Business Analyst by profession and I want to make learning fun and easy 🙂

No responses yet