0

Please help stuck on functions how do they work?and how can I use it in coding

19th Jan 2022, 7:40 PM
Okere Samuel
Okere Samuel - avatar
6 odpowiedzi
+ 3
Functions are blocks of code that you can "call" to execute: //declaring the function function funcName(){ //code return "some functions return values, like this string"; } //calling the function and showing the return in the console console.log(funcName()); //console.log() is like a function!
19th Jan 2022, 8:19 PM
CGM
CGM - avatar
+ 1
Cristian Gabriel Mazzulla Where are the code lines inside functions stored?
19th Jan 2022, 8:31 PM
Œ ㅤ
Œ ㅤ - avatar
+ 1
Quoi Runtime I don't know the technical details. As I understand it, functions are just pieces of code, stored like any other piece of code, but with an address that you "go to" when you want to execute it. The truth is that I'm not sure, I only know that you put the name of the function() and it works😆 Oh but I'm sure NO, 'a=67' is not an attribute and 'a' may not be defined until the function is called.
20th Jan 2022, 3:18 AM
CGM
CGM - avatar
0
Quoi Runtime ? I think I don't understand the question😅
19th Jan 2022, 8:38 PM
CGM
CGM - avatar
0
Cristian Gabriel Mazzulla In Python, functions are objects. So where exactly is the code block inside the function stored? Here's what I mean: def func(foo): a = 67 print(a % 9) 'func' is an object, so am I safe to assume that it holds the 'a = 67...' code data in an attribute of itself? Where is the code inside stored?
20th Jan 2022, 2:44 AM
Œ ㅤ
Œ ㅤ - avatar
0
Cristian Gabriel Mazzulla Suppose this function:- # meaningless garbage tbh lol def foo(): print("Hello") print(78) True | False So I'm assuming something like:- foo.__code = """print(\"Hello\") print(78) True | False""" And exec(foo.__code)
21st Jan 2022, 8:37 AM
Œ ㅤ
Œ ㅤ - avatar