Answer the question
In order to leave comments, you need to log in
How to set a variable to a constant?
Hello!
The question is: there is a constant that functions sometimes use in their calculations, looks something like this:
value = 3
def():
#где-то здесь это value применяется
...
def(..):
...
def(...):
#и здесь тоже, например
....
...
Answer the question
In order to leave comments, you need to log in
In the code you provided, you need to add an increment by one after each call to the variable:
Or there is a more complicated way - write a special class that will intercept any call to a certain attribute, return the value of the corresponding variable, and increment it by one.
Or you can also take the count iterator from the itertools standard library and access it via next().
But you are probably better off using the very first method I suggested.
and do as you have in the code now, although in this case the variable will be global, which is not very good
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question