Python, counter atomic increment

前端 未结 3 1012
庸人自扰
庸人自扰 2020-12-13 09:04

How can I translate the following code from Java to Python?

AtomicInteger cont = new AtomicInteger(0);

int value = cont.getAndIncrement();
3条回答
  •  感情败类
    2020-12-13 09:14

    itertools.count returns an iterator which will perform the equivalent to getAndIncrement() on each iteration.

    Example:

    import itertools
    cont = itertools.count()
    value = next(cont)
    

提交回复
热议问题