Page 1 of 1

Just started Python today... first question

Posted: Tue Feb 01, 2022 3:39 am
by FlyingDoggyJake
Hi all, I was a VB6 programmer about 20 years ago. I'm trying to get back into the fun again. Things have changed a lot. At any rate, my first question is that I wrote an extremely basic first program and saved it to a .py file. The code is as follows:

Code: Select all

for x in range(0, 150, 1):
    print("All work and no play makes Jake a dull boy. ", end = "")



When I executed it, the python console opened and it did exactly what I thought it would but I was shocked at how slow the loop ran. I mean the 150 lines printed in about 9 seconds. I had assumed that the loop would have been so lightning quick that I would not have even been able to see the lines rising on the screen. 20 years ago if I had done the same program in VB6 it would have been that lightning quick... so what gives? The computers now are waaaaay faster. I'm confused.

Re: Just started Python today... first question

Posted: Tue Feb 01, 2022 6:30 am
by Articha
That's because you using print function. To prevent spam, python adding delay between them

Use write to file instead:

Code: Select all

file = open("text.txt", "w")
for x in range(0, 150, 1):
    file.write("All work and no play makes Jake a dull boy. ", end = "")
file.close()

And your code will be executed instantly

Re: Just started Python today... first question

Posted: Tue Feb 01, 2022 7:33 am
by FlyingDoggyJake
Ahhh that makes sense! Thanks Articha!