While I started teaching Python, one of the most common beginner questions I got was about Armstrong numbers.
It’s a simple concept, but it’s also a great way to practice loops, conditionals, and functions in Python.
In this tutorial, I’ll show you three different methods to check N-digit Armstrong numbers in Python. I’ll also provide complete code examples that you can run directly.
What is an Armstrong Number?
An Armstrong number (also called a narcissistic number) is a number that is equal to the sum of its own digits raised to the power of the number of digits.
For example:
- 153 is an Armstrong number because:
( 1^3 + 5^3 + 3^3 = 153 ) - 9474 is also an Armstrong number because:
( 9^4 + 4^4 + 7^4 + 4^4 = 9474 )
Method 1 – Use Loops in Python
When I first learned about Armstrong numbers, I started with a simple loop-based approach. This method is easy to understand and perfect for beginners.
Code:
# Method 1: Using Loops
def is_armstrong(num):
digits = str(num)
power = len(digits)
total = 0
for d in digits:
total += int(d) ** power
return total == num
# Example usage
number = 153
if is_armstrong(number):
print(f"{number} is an Armstrong number.")
else:
print(f"{number} is not an Armstrong number.")Output:
153 is an Armstrong number.You can refer to the screenshot below to see the output.

This method is simple and helps you clearly see how the calculation works. It’s great for small numbers and when you’re just starting.
Method 2 – Use Python List Comprehension
After I got comfortable with loops, I switched to Python’s list comprehensions. They make the code shorter and more Pythonic.
Code:
# Method 2: Using List Comprehension
def is_armstrong(num):
digits = str(num)
power = len(digits)
return sum([int(d) ** power for d in digits]) == num
# Example usage
number = 9474
if is_armstrong(number):
print(f"{number} is an Armstrong number.")
else:
print(f"{number} is not an Armstrong number.")Output:
9474 is an Armstrong number.You can refer to the screenshot below to see the output.

This method is concise and efficient, making it perfect for quick checks. I often use it when I’m writing scripts that need to be clean and readable.
Method 3 – Find Armstrong Numbers in a Range
In real-world coding, I often need to check multiple numbers at once. This method lets you find all Armstrong numbers within a given range.
Code:
# Method 3: Find Armstrong Numbers in a Range
def armstrong_in_range(start, end):
result = []
for num in range(start, end + 1):
digits = str(num)
power = len(digits)
total = sum(int(d) ** power for d in digits)
if total == num:
result.append(num)
return result
# Example usage
print("Armstrong numbers between 100 and 10000 are:")
print(armstrong_in_range(100, 10000))Output:
Armstrong numbers between 100 and 10000 are:
[153, 370, 371, 407, 1634, 8208, 9474]You can refer to the screenshot below to see the output.

This method is practical when you want to explore Armstrong numbers across a range. It’s also handy for assignments or coding challenges.
Conclusion
In this tutorial, I showed you three different ways to check Armstrong numbers in Python:
- Using loops for clarity.
- Using list comprehension for clean, concise code.
- Using a range-based function to find multiple Armstrong numbers.
Each method has its own use case, and I encourage you to try them all.
Once you’re comfortable, you can even extend these methods to larger numbers or optimize them for performance.
You may read:
- Concatenate a List of Strings into a Single String in Python
- Get Unique Values from a List in Python
- Replace Values in a List Using Python
- Shuffle a List in Python

I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.