0
Def in Python
Well i have a simple question with (def) code in Python and maybe i already know the answer.. but i need a explanation! Why when i create a def in Python with one variable inside and i try to print this variable outside the def, the program show error?? https://code.sololearn.com/ci62143vyF0y/?ref=app
3 Answers
+ 2
All variables declared inside functions will by default be deleted, when the function call ends.
This can be prevented by declaring the variables global.
https://code.sololearn.com/cxgyYwjY22Kp/?ref=app
+ 2
Scope of 'var' is within function example1().
If you want to print the value of var', u have to return the value from example1(), capture the value, then print it.