Skip to content
Patppuccin
Main Navigation
Expeditions
Curations
Ruminations
Labs
Projects
Persona

Appearance

Sidebar Navigation

Faith & Theology

Genesis Chapter 1

Science & Nature

Health & Medicine

People & Culture

Languages & Comms

Philosophy

History

Economics

Art & Literature

Tech & Engineering

History of Computing

Fundamentals of Computing

Systems & Architecture

The Linux OS

Hardware & Embedded Systems

Networking & Internet

Computer Networking

Programming & Paradigms

Bash

Concepts

Authentication and Authorization

Infrastructure as Code (IaC)

Free and Open Source (FOSS)

Variable Naming Cases

Version Control Systems

Golang

JavaScript

PowerShell

PowerShell Error Handling

PowerShell Flow Control and Loops

PowerShell Functions

PowerShell Modules

PowerShell Basics

Python

Data Types and Variables

Flow Control and Loops

Fundamentals

Getting Started

Methods and Functions

Operators

Python

Rust Programming Language

Software Engineering

Application Development

Infrastructure & Cloud

Amazon Web Services

Amazon Web Services

Cloud Technology

DevOps & Automation

Kubernetes

Terraform

Security Engineering

Data Systems

Computational Intelligence

Design & Interaction

Tooling & Utilities

Git

Secure Shell (SSH)

On this page

Operators in Python ​

Operators are entities that are used to perform operations on variables and values. Python provides the following operator types

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

Arithmetic Operators ​

These are used with numeric values to perform numeric calculations on them.

OperatorNameExample
+Additionx + y
-Subtractionx - y
*Multiplicationx * y
/Divisionx / y
%Modulusx % y
**Exponentiationx ** y
//Floor Divisionx // y

Assignment Operators ​

The assignment operators are used to assign values to variables.

OperatorExampleSame As
=x = 5x = 5
+=x += 3x = x + 3
-=x -= 3x = x - 3
*=x *= 3x = x * 3
/=x /= 3x = x / 3
%=x %= 3x = x % 3
//=x //= 3x = x // 3
**=x **= 3x = x ** 3
&=x &= 3x = x & 3
|=x |= 3x = x | 3
^=x ^= 3x = x ^ 3
>>=x >>= 3x = x >> 3
<<=x <<= 3x = x <<= 3

Comparison Operators ​

They are used to compare two values.

OperatorNameExample
==Equalx == y
!=Not Equalx !=
>Greater Thanx > y
<Lesser Thanx < y
>=Greater Than or Equal Tox >= y
<=Lesser Than or Equal Tox <= y

Logical Operators ​

Logical Operators are used to combine conditional statements.

OperatorDescriptionExample
andReturns true if both statements are truex < 5 and x < 10
orReturns true if any of the statements is truex < 5 or x < 4
notReverses the result - true is false and vice versanot (x < 5)

Identity Operators ​

Identity operators are used to compare objects if they are the actual same objects. These do not check for the similarity of content within the variable, but the actual memory location.

OperatorDescriptionExample
isReturns true if both variables are the same objectx is y
is notReturns true is both variables are different objectsx is not y

Membership Operators ​

Membership operators are used to test if a sequence is presented in an object of comparison.

OperatorDescriptionExample
inReturns true if a sequence with the specified value is present in the objectx in y
not inReturns true if a sequence with the specified value is not present in the objectx not in y

Bitwise Operators ​

Bitwise operators are used to compare binary numbers.

OperatorNameDescription
&ANDSets each bit to 1 if both bits are 1
|ORSets each bit to 1 if one of the two bits is 1
^XORSets each bit to 1 if only one of two bits is 1
~NOTInverts the bits
<<Zero Fill Left ShiftShift left by pushing zeros in from the right and let the leftmost bits fall off
>>Signed Right ShiftShift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off

Updated at:

Pager
Previous pageMethods and Functions
Next pagePython

Made with ❤️ and Vitepress

Copyright © 2025 Patrick Ambrose.