Цикл for в Python

Рассмотрим файл for_loop.py

for i in range(1,4):print(i)

python for_loop.py

1
2
3

Всё работает прекрасно. Обратите внимание, что выведены были только i от 1 до 3. 4 python не вывел.

Читать однострочные скрипты неудобно. Обычно каждое действие стараются записать на отдельной строке.

for i in range(1,3): print(i)

python for_loop.py

1
2
3

Если написать код без хотя бы одного пробела перед print

for i in range(1,4): print(i)

то работать код не будет. Получится ошибка

File "/home/andrei/python/for_loop.py", line 2 print(i) ^ IndentationError: expected an indented block

Поэтому нужно поставить перед print пробел

Пример с _

retries=3 retries_ = abs(int(retries)) for _ in range(retries_ + 1): print(_)

1
2
3
4

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: