Categories: Programming

Python Comparision Operators – Python Basics

Comparison Operators in python are pretty straight forward if you have any sort of background in Mathematics.

Related Post

First we’ll present a table of comparison operators and then work through some examples:

OperatorDescriptionExmple
==if two values of the operands are equal,
then the condition becomes true
‘1’ == ‘1’ is true
!=if two values of the operands are not equal,
then condition becomes true
‘1’ != ‘2’ is true
>If the value of the left operand is greater
than the value of the right operand,
then the condition becomes true.
2 > 1 is true
<If the value of the right operand is greater
than the value of the left operand,
then the condition becomes true.
2 < 1 is false
>= If the value of the left operand is greater
or equal to the value of the right operand,
then the condition becomes true.
2 >= 1 is true
<= If the value of the right operand is greater
or equal to the value of the left operand,
then the condition becomes true.
2 <= 1 is false

Examples

Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 1 <= 2
True
>>> 2 >= 3
False
>>> 1 == 1
True
>>> 'a' == 1
False
>>> type('a') == str
True
>>> 
Aditya Kumar

Share
Tags: Python Python Basic Tutorial

Recent Posts

  • Programming

Mastering Print Formatting in Python: A Comprehensive Guide

In Python, the print() function is a fundamental tool for displaying output. While printing simple…

10 months ago
  • Programming

Global Variables in Python: Understanding Usage and Best Practices

Python is a versatile programming language known for its simplicity and flexibility. When working on…

10 months ago
  • Programming

Secure Your Documents: Encrypting PDF Files Using Python

PDF (Portable Document Format) files are commonly used for sharing documents due to their consistent…

10 months ago
  • Programming

Creating and Modifying PDF Files in Python: A Comprehensive Guide with Code Examples

PDF (Portable Document Format) files are widely used for document exchange due to their consistent…

10 months ago
  • Programming

Boosting Python Performance with Cython: Optimizing Prime Number Detection

Python is a high-level programming language known for its simplicity and ease of use. However,…

10 months ago
  • Programming

Using OOP, Iterator, Generator, and Closure in Python to implement common design patterns

Object-Oriented Programming (OOP), iterators, generators, and closures are powerful concepts in Python that can be…

10 months ago

This website uses cookies.