0
accesse to global variable from inside the class
i wont to change the value of global var from class when i call function fom it in cpp we can use pointer ,are there pointer in python or some thing like that
2 Respostas
+ 11
use 'global' keyword
name = 'a'
def c():
global name
name = 'b'
print(name)
c()
print(name)
+ 2
There are no pointers in Python. But if you just want to know the value of a global variable without changing it, you can simply use it directly, no problem.
https://docs.python.org/3/faq/programming.html#what-are-the-rules-for-local-and-global-variables-in-python
And if you do want to modify it, just write
global my_variable inside the function, like Mert suggested.