Skip to content

Print for loop in one line python | Example code

  • by

Let’s see some Print for loop in single-line python examples.

Python Print 1 to 10 in One-line code

Compress Two Lines in One Line (print from 0 to 9).

for i in range(10): print(i)

Output::

Print for loop in one line python

Print square of the number in for loop one line python

List Comprehension, The code squares the first ten numbers and stores them in the list squares.

print([i**2 for i in range(10)])

Output:

Print square of the number in for loop one line python

Do comment if you have any doubts and suggestions on this Python for loop topic.

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.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading