How to create global variable in Pyhton and use this variable inside the function? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to create global variable in Pyhton and use this variable inside the function?

global variable

16th Oct 2017, 12:13 PM
Василь Хамуляк
Василь Хамуляк - avatar
2 Answers
0
thank you
16th Oct 2017, 2:02 PM
Василь Хамуляк
Василь Хамуляк - avatar
- 1
1 . any variable created outside any func. is a global by default... 2 . any variable declaired in any func. is a local variable...to use it/access it out side the func. or in other functions...u have to make it global.. example: a=5 def hello() : print(a) global b b=7 print(b) ## outside function; accessing b >>> 5 7
16th Oct 2017, 1:18 PM
sayan chandra
sayan chandra - avatar