Doubt on for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Doubt on for loop?

for i in range(1,6): for j in range(i): print("*",end=" ") print() Here in the last line print() what we are calling to print. Without using that print() statement why all stars comes in single line even we give end="". Thank you

4th May 2021, 12:33 PM
Praneeth Kumar
Praneeth Kumar - avatar
3 Answers
+ 2
Because after the inner loop ends you need to break a line. Which that empty print statement does.
4th May 2021, 12:37 PM
Krish
Krish - avatar
0
Thank you now I understand for breaking the loop we give print() at the end. Thank you brother for your reply
4th May 2021, 12:39 PM
Praneeth Kumar
Praneeth Kumar - avatar
0
Yeah it's not for breaking the line but allowing the console to change line or you can say a line break.
4th May 2021, 4:35 PM
Krish
Krish - avatar