Avatar ·

Global variables in Python: save the local variable from call to call function

📁 function, Advanced Python Topics, AI, work

I have a function that needs to keep a value from call to call, while this value is used only in this function. How to use global variables in Python? I tried to write something similar:

someglobalvar = 0
def incrementglobalvar():
    someglobalvar = someglobalvar + 1

but this code does not work. Maybe there are other ways to solve this problem?