accesse to global variable from inside the class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

27th Nov 2018, 11:14 AM
Omar Muhammad Nofal
Omar Muhammad Nofal - avatar
2 Answers
+ 11
use 'global' keyword name = 'a' def c(): global name name = 'b' print(name) c() print(name)
27th Nov 2018, 12:40 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 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.
27th Nov 2018, 12:44 PM
Kishalaya Saha
Kishalaya Saha - avatar