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
Release: 2019-07-08 10:18:09
Original
7096 people have browsed it

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=',')
Copy after login

Output results

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
Copy after login
Copy after login

2 , use while loop

i= 1
while i <= 20:
    print(i,end=&#39;,&#39;)
    i += 1
Copy after login

Output results

1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
Copy after login
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template