[Python] How can I access global variable inside class in Python

Discussão em 'Python' iniciado por Stack, Outubro 24, 2024.

  1. Stack

    Stack Membro Participativo

    I have this:

    g_c = 0

    class TestClass():
    global g_c
    def run(self):
    for i in range(10):
    g_c = 1
    print(g_c)

    t = TestClass()
    t.run()

    print(g_c)


    how can I actually modify my global variable g_c?

    Continue reading...

Compartilhe esta Página