A for loop or while loop or range() function is the way to write a program to print the first 10 natural numbers in Python.
Program to print the first 10 natural numbers in Python
A simple example code displays natural numbers from 1 to n.
Using for loop
It displays natural numbers from 1 to 10.
num = 10
for i in range(1, num + 1):
print(i, end=" ")
Output:
Using while loop
i = 1
while i <= 10:
print(i),
i = i + 1
Output:
1
2
3
4
5
6
7
8
9
10
Do comment if you have any doubts or suggestions on this Python natural number code.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.