How to access a function local variable outside the function in Python

2 Answers

0 votes
def fun():
   global val
   val = 746


fun()

print(val)




'''
run:

746

'''

 



answered Mar 2, 2023 by avibootz
0 votes
def fun():
   fun.val = 74637 # function attribute


fun()

print(fun.val)




'''
run:

74637

'''

 



answered Mar 2, 2023 by avibootz

Related questions

3 answers 330 views
1 answer 152 views
1 answer 212 views
1 answer 165 views
4 answers 363 views
...