0
Are functions being executed when they're defined? Or does the function's code run when it is called without the "def"?
4 ответов
+ 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')
+ 1
Thanks everyone!
0
The functions code run when called
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