+ 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?

31st Aug 2017, 8:37 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
42 Answers
+ 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
31st Aug 2017, 11:20 AM
sayan chandra
sayan chandra - avatar
+ 3
if var not declared in function : var=global elif var is in function : if var has keyword global : var= global else : var= local
31st Aug 2017, 11:38 AM
sayan chandra
sayan chandra - avatar
+ 1
Thank you for that code! so simple! I will try in the evening and let you know if it works
31st Aug 2017, 11:26 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
31st Aug 2017, 10:59 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
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"
31st Aug 2017, 11:01 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
ok.. thank you
31st Aug 2017, 11:04 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
because i need to know why this one didnt work
31st Aug 2017, 11:14 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
the 2.0 isnt as efficient there's repeated code, i dont like that
31st Aug 2017, 11:15 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
so the return statement why cant other functions use a variable that is 'returned' by a function
31st Aug 2017, 11:16 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
even after correcting that it still didnt work because of 'result' not being passed to the 'finish()' function
31st Aug 2017, 11:18 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
Thank you Sandra 😃
31st Aug 2017, 11:21 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
now we are getting somewhere
31st Aug 2017, 11:21 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
now how do i make result global?
31st Aug 2017, 11:21 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
i camt believe i just called you Sandra 😅 sorry 😁
31st Aug 2017, 11:25 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
is it possible to declare a variable as local?
31st Aug 2017, 11:34 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
but not inside a function?
31st Aug 2017, 11:35 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
😂😂😂😂 local means created in func without global key word
31st Aug 2017, 11:35 AM
sayan chandra
sayan chandra - avatar
0
Hoooo 😮😮😮
31st Aug 2017, 11:36 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
that mustve sounded pretty funny then 😅😅😅😂
31st Aug 2017, 11:37 AM
Tinotenda Makuza
Tinotenda Makuza - avatar
0
cool answer!
31st Aug 2017, 11:44 AM
Tinotenda Makuza
Tinotenda Makuza - avatar