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

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • 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.  Get Python Dictionary Keys as List
  • 2.  Drop Last Row of pandas DataFrame
  • 3.  pandas to_pickle – Write DataFrame to Pickle File
  • 4.  pandas floor – Find the Floor of a Column Using Numpy floor
  • 5.  Using Python to Repeat Characters in String
  • 6.  Get Random Value from Dictionary in Python
  • 7.  Divide Each Element in List by Scalar Value with Python
  • 8.  Using Python to Calculate Average of List of Numbers
  • 9.  How to Check if Character is Uppercase in Python
  • 10.  Comparing Datetimes 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