Whats the python equivalent of the setInterval () function in javascript | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Whats the python equivalent of the setInterval () function in javascript

9th Aug 2020, 9:00 AM
...
... - avatar
7 Réponses
+ 3
If you want to do something simple like put a pause in program execution, the .sleep() method of the time module would do it. For more complex things have a look at https://stackoverflow.com/questions/2697039/JUMP_LINK__&&__python__&&__JUMP_LINK-equivalent-of-setinterval
9th Aug 2020, 11:18 AM
Alan Beveridge
Alan Beveridge - avatar
+ 2
For example: from time import sleep i = 0 while i < 5: print('hello') i += 1 sleep(0.2)
9th Aug 2020, 12:28 PM
JaScript
JaScript - avatar
+ 2
Thanks yall Really really helpful
9th Aug 2020, 4:41 PM
...
... - avatar
+ 1
what the sleep method does is to pause the function from executing for a particular time before it continue. it does not run the function at a set interval like setInterval() in JavaScript
6th Nov 2020, 1:52 PM
Oyelakin Dotun Peter
Oyelakin Dotun Peter - avatar
+ 1
import time from datetime import datetime i = 0 def setInterval(second): # code start print(i) print(datetime.now().strftime("%H:%M:%S")) # code end time.sleep(second) setInterval(second) setInterval(1)
9th Mar 2022, 3:02 PM
आगरी कोळी World
16th Nov 2020, 5:26 PM
...
... - avatar