LoginSignup
3
4

More than 3 years have passed since last update.

呼び出すごとに1増える関数作りたい!ので作ってみた

Posted at
test.py
def fueru():
    global TanakaAtomicBomb
    if 'TanakaAtomicBomb' in globals():
        TanakaAtomicBomb += 1
        return TanakaAtomicBomb
    else:
        TanakaAtomicBomb = 0
        return TanakaAtomicBomb

使い方

下記の通り

print(fueru())
print(fueru())
print(fueru())
print(fueru())
print(fueru())
print(fueru())
$ python test.py
0
1
2
3
4
5
6
3
4
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4