Home >Backend Development >Python Tutorial >How to print integers from 1 to 20 in python

How to print integers from 1 to 20 in python

silencement
silencementOriginal
2019-06-26 13:04:437092browse

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=&#39;,&#39;)
    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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn