0

Pondering about line 4

import time def after(seconds, func): time.sleep(seconds) func() is line no 4 referring " return func()" ??

29th Dec 2018, 2:23 AM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
7 Respostas
+ 6
In your function, you have 2 parameters - one to select how long the program should pause for and the other that indicates a certain function from the program. What the function will do is wait a short while (depending on what the first parameter is) and then run the function specified by the second parameter. As you're just running the function, you therefore don't need to return it.
29th Dec 2018, 2:32 AM
Faisal
Faisal - avatar
+ 2
There is some problems with your indentation, that'll raise an exception
29th Dec 2018, 2:39 AM
Gordon
Gordon - avatar
+ 2
No, you don't need to indicate a function is function. You put () to execute it
29th Dec 2018, 2:45 AM
Gordon
Gordon - avatar
0
so here i am putting the () next to func parameter at line 4 to indicate that second parameter is gonna be a function, it that right ?
29th Dec 2018, 2:44 AM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
0
import time def after(seconds, func): time.sleep(seconds) func() def hello(): print("Hello World") after(5, hello) Output: after 5 seconds Hello World # pls explain in details
29th Dec 2018, 2:51 AM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar
0
Understood. Thanks
29th Dec 2018, 3:13 AM
🄼🄼🄷🄺
🄼🄼🄷🄺 - avatar