Home > Article > Backend Development > How to print integers from 1 to 20 in python
Methods to print integers between 1 and 20:
1. Use for loop
for i in range(1,21): print(i,end=',')
Output results
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
2 , use while loop
i= 1 while i <= 20: print(i,end=',') i += 1
Output results
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
The above is the detailed content of How to print integers from 1 to 20 in python. For more information, please follow other related articles on the PHP Chinese website!