0

Are functions being executed when they're defined? Or does the function's code run when it is called without the "def"?

28th Dec 2016, 1:49 AM
Hyrum
Hyrum - avatar
4 Antworten
+ 1
They are not executed, however the code around them is executed. For example: print('Im executed right away') @my_decorator('Im also executed') def my_func(): print('Im not executed till the function is called')
28th Dec 2016, 2:46 AM
James Durand
James Durand - avatar
+ 1
Thanks everyone!
28th Dec 2016, 8:53 PM
Hyrum
Hyrum - avatar
0
The functions code run when called
28th Dec 2016, 1:39 PM
Himanshu Vishwakarma
0
Def my_function(x): #function defined x * 2 my_function(4). #function called You always need to define a funcation before calling it...for example, if you wrote the above code the other way round (call the function first), it will produce an error
28th Dec 2016, 5:27 PM
Paul Bartholomew