+ 1
How To Pass Variables In Python
i thought the return statement sort of allowed other functions to use a variable But that doesnt seem to be the case so if it doesn't, then what does it do? And how can i make a variable accessible to other functions?
42 Réponses
+ 1
hmmm
now you asked the right question
thers 2 type of variable
local
global
locals r created in func only used by that function
globals r created globally
not in any func. body
any func can use them
as ur all result variables r in functions they r local ; thus cant be used by any other func
+ 3
if var not declared in function :
var=global
elif var is in function :
if var has keyword global :
var= global
else :
var= local
+ 1
Thank you for that code! so simple! I will try in the evening and let you know if it works
0
this is a calculator i made trying to use return to allow other functions to use a variable 'result'
but i was always being told that "result is undefined"
0
ok.. thank you
0
because i need to know why this one didnt work
0
the 2.0 isnt as efficient
there's repeated code, i dont like that
0
so the return statement
why cant other functions use a variable that is 'returned' by a function
0
even after correcting that it still didnt work
because of 'result' not being passed to the 'finish()' function
0
Thank you Sandra 😃
0
now we are getting somewhere
0
now
how do i make result global?
0
i camt believe i just called you Sandra 😅
sorry 😁
0
is it possible to declare a variable as local?
0
but not inside a function?
0
😂😂😂😂
local means created in func without global key word
0
Hoooo 😮😮😮
0
that mustve sounded pretty funny then 😅😅😅😂
0
cool answer!