0

is 'global' in python like 'public' in java?

when i write global in python does it just let me use the variables that i write after the word 'global'? when do i use 'global'? is 'global' in python like 'public' in java?

6th Jul 2020, 8:50 PM
Yahel
Yahel - avatar
4 odpowiedzi
+ 1
Global variables are the one that are defined and declared outside a function and we need to use them inside a function. https://www.google.com/amp/s/www.geeksforgeeks.org/global-local-variables-JUMP_LINK__&&__python__&&__JUMP_LINK/amp/
6th Jul 2020, 8:52 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
0
Emanuel Maliaño thanks! But how is it possible that variable s could be 2 thing in the same time? In one of the examples in the site they showed that the variable s is 2 things.. how?
6th Jul 2020, 9:01 PM
Yahel
Yahel - avatar
0
The variable s does not have two states at the same time, but has two different scopes, the first assignment is within the function, so that variable is part of the function and cannot be accessed from outside. The second one is in scope. global so you can access it from any part of your program but if you access this variable within a function and you want to change its value you must use the global keyword.
6th Jul 2020, 9:11 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
0
Emanuel Maliaño got it! Thanks!
6th Jul 2020, 9:12 PM
Yahel
Yahel - avatar