-3

how can I check in a statement if a variable is an integer?

like for string, we can say:

if i == " "
    return something

how would I say: if i == integer??

  • 1
    You should read these consistent answers: https://stackoverflow.com/questions/152580/whats-the-canonical-way-to-check-for-type-in-python – ggrelet Apr 18 '19 at 07:37

2 Answers2

2

Like this:

if type(i) == int:
     do_this()

Or like this:

if isinstance(i, int):
     do_this()

You will find more info here: What's the canonical way to check for type in Python? (of which I think your question is a duplicate)

ggrelet
  • 1,071
  • 7
  • 22
0

Using isinstance:

for kee, val in valStore.items():
     if isinstance(key, int):
          writehist.writerow([key] + [val])
DirtyBit
  • 16,613
  • 4
  • 34
  • 55