• 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
  • VBA
  • 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.  Using Python to Reverse Tuple
  • 2.  Python Logging Timestamp – Print Current Time to Console
  • 3.  How to Check if Number is Divisible by 3 in Python
  • 4.  How to Check if Variable Exists in Python
  • 5.  Using Python to Replace Backslash in String
  • 6.  Python Get Number of Cores Using os cpu_count() Function
  • 7.  How to Check if Set is Empty in Python
  • 8.  How to Find the Longest String in List in Python
  • 9.  Python gethostbyname() Function – Get IPv4 Address from Name
  • 10.  Adjusting Python Turtle Screen Size with screensize() Function

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

The Programming Expert is a compilation of hundreds of code snippets to help you find solutions to your problems in Python, JavaScript, PHP, HTML, SAS, and more.

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 © 2022 · The Programming Expert · About · Privacy Policy