• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / Check if Number is Larger than N in Python

Check if Number is Larger than N in Python

July 8, 2022 Leave a Comment

To check if a number if larger than a given number N in Python, the easiest way is with the greater than > operator and an if statement.

num = 12
N = 10

if num > N:
    print("num is larger than N")
else:
    print("num is smaller than N")

#Output:
num is larger than N

When working with numbers in Python, the ability to easily be able to make comparisons is important.

One such case is if you want to check if a number is larger than a given number N.

To check if a number is greater than another, you can use the greater than > operator and an if statement.

Below is a simple example showing you how to check if a number is greater than another number in Python.

num = 12
N = 10

if num > N:
    print("num is larger than N")
else:
    print("num is smaller than N")

#Output:
num is larger than N

If you want to put this in a function, you can do the following.

def largerThan(num, N):
    if num > N:
        print("num is larger than N")
    else: 
        print("num is smaller than N")

largerThan(12,10)

#Output:
num is larger than N

Check if Number is Smaller than N in Python

If you want to go the other way and check if a number is smaller than a given number N, then you can use the less than operator <.

Below is a simple example showing you how to check if a number is less than another number in Python.

num = 5
N = 10

if num < N:
    print("num is smaller than N")
else:
    print("num is larger than N")

#Output:
num is smaller than N

Hopefully this article has been useful for you to learn how to check if a number is larger than N in Python.

Other Articles You'll Also Like:

  • 1.  Python Prime Factorization – Find Prime Factors of Number
  • 2.  Remove All Instances of Value from List in Python
  • 3.  How to Remove All Occurrences of a Character in a List Using Python
  • 4.  pandas variance – Compute Variance of Variables in DataFrame
  • 5.  Python max float – What’s the Maximum Float Value in Python?
  • 6.  Using Python to Check if Queue is Empty
  • 7.  pandas interpolate() – Fill NaN Values with Interpolation in DataFrame
  • 8.  How to Sort Numbers in Python Without Sort Function
  • 9.  Get Day Name from Datetime in pandas DataFrame
  • 10.  How to Concatenate Tuples in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy